C#编程操作应用程序.doc

上传人:scccc 文档编号:12152221 上传时间:2021-12-02 格式:DOC 页数:2 大小:22.24KB
返回 下载 相关 举报
C#编程操作应用程序.doc_第1页
第1页 / 共2页
C#编程操作应用程序.doc_第2页
第2页 / 共2页
亲,该文档总共2页,全部预览完了,如果喜欢就下载吧!
资源描述

《C#编程操作应用程序.doc》由会员分享,可在线阅读,更多相关《C#编程操作应用程序.doc(2页珍藏版)》请在三一文库上搜索。

1、;C#编程操作应用程序在C#中如何判断一个文件是否存在?System.IO.File.Exists("文件路径")例如System.IO.File.Exists("D:Program Files腾讯游戏地下城与勇士startTenio.ini")c# 如何删除指定路径下的指定文件?System.IO.File.Delete("文件完整路径");例如System.IO.File.Delete("D:Program Files腾讯游戏地下城与勇士startTenio.ini");c#打开指定的应用程序System.Di

2、agnostics.Process.Start("D:Program Files腾讯游戏地下城与勇士startDNFchina.exe")如何使用C#操作快捷方式(获取快捷方式属性、创建快捷方式)右键“引用”,“添加引用”,选择“COM组件”,找到“Windows Script Host Object Model”,然后确定。第一步 创建一个项目第二步 引用COM组件第三步 编写创建快捷方式的代码创建快捷方式/ 声明操作对象IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass();/

3、 创建一个快捷方式IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut("c:yeaicc.lnk");/ 关联的程序shortcut.TargetPath = "notepad.exe"/ 参数shortcut.Arguments = "c:yeaicc.txt"/ 快捷方式描述,鼠标放到快捷方式上会显示出来哦shortcut.Description = "我的快捷方式-yeaicc&

4、quot;/ 全局热键shortcut.Hotkey = "CTRL+SHIFT+N"/ 设置快捷方式的图标,这里是取程序图标,如果希望指定一个ico文件,那么请写路径。shortcut.IconLocation = "notepad.exe, 0"/ 保存,创建就成功了。shortcut.Save();一个完整的实例:namespace DNF static class Program / <summary> / 应用程序的主入口点。 / </summary> STAThread static void Main() Appli

5、cation.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); string DNFOldLnkFile1 = "D:Program Files腾讯游戏地下城与勇士地下城与勇士.lnk" string DNFOldLnkFile2 = "C:UserspengDesktop地下城与勇士.lnk" string TargetExeFile = "D:Program Files腾讯游戏地下城与勇士startDNFchina.exe" /s

6、tring StartDNFfile = "D:Program Files腾讯游戏地下城与勇士start地下城与勇士" /string FileDeleteInformation = "文件未被删除,可能无法正常运行游戏n" try DeleteOldFile(DNFOldLnkFile1); DeleteOldFile(DNFOldLnkFile2); catch (Exception) MessageBox.Show("陈鹏提示:文件删除失败"); try CreateNewLnkFile(DNFOldLnkFile1, Targ

7、etExeFile); CreateNewLnkFile(DNFOldLnkFile2, TargetExeFile); catch (Exception) MessageBox.Show("陈鹏提示:快捷方式创建失败"); try System.Diagnostics.Process.Start(DNFOldLnkFile2); catch (Exception) MessageBox.Show("陈鹏提示:DNF已被开启者取消"); /Application.Run(new Form1(); static void DeleteOldFile(str

8、ing FilePath) if (System.IO.File.Exists(FilePath) System.IO.File.Delete(FilePath); static void CreateNewLnkFile(string FilePath,string TargetExeFile) / 声明操作对象 IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass(); / 创建一个快捷方式 IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntim

9、eLibrary.IWshShortcut)shell.CreateShortcut(FilePath); / 关联的程序 shortcut.TargetPath = TargetExeFile; / 参数 /shortcut.Arguments = "c:yeaicc.txt" / 快捷方式描述,鼠标放到快捷方式上会显示出来哦 shortcut.Description = "陈鹏制作" / 全局热键 /shortcut.Hotkey = "CTRL+SHIFT+N" / 设置快捷方式的图标,这里是取程序图标,如果希望指定一个ico文件,那么请写路径。 /shortcut.IconLocation = "notepad.exe, 0" / 保存,创建就成功了。 shortcut.Save(); .'

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1