C# 桌面创建快捷键方式
2015-07-26 22:30
253 查看
首先,导入COM组件Windows Script Host Object Model
其次,引用命名空间using IWshRuntimeLibrary;
//判断创建快捷键方式桌面是否存在
string deskTop = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
if(System.IO.File.Exists(deskTop + "\\上传更新程序.lnk")) //
{
// System.IO.File.Delete(deskTop + "\\上传更新程序.lnk");//删除原来的桌面快捷键方式
return;
}
//注:如果桌面有现准备创建的快捷键方式,当程序执行创建语句时会修改桌面已有快捷键方式,程序不会出现异常
WshShell shell = new WshShell();
//快捷键方式创建的位置、名称
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut( Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + "上传更新程序.lnk");
shortcut.TargetPath = @Application.StartupPath+"\\auto.AutoTranUpdate.exe"; //目标文件
shortcut.WorkingDirectory = System.Environment.CurrentDirectory;//该属性指定应用程序的工作目录,当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。
shortcut.WindowStyle = 1; //目标应用程序的窗口状态分为普通、最大化、最小化【1,3,7】
shortcut.Description = "自动更新程序"; //描述
shortcut.IconLocation = Application.StartupPath + "\\App.ico"; //快捷方式图标
shortcut.Arguments = "";
shortcut.Hotkey = "CTRL+ALT+F11";
// 快捷键
shortcut.Save(); //必须调用保存快捷才成创建成功
其次,引用命名空间using IWshRuntimeLibrary;
//判断创建快捷键方式桌面是否存在
string deskTop = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
if(System.IO.File.Exists(deskTop + "\\上传更新程序.lnk")) //
{
// System.IO.File.Delete(deskTop + "\\上传更新程序.lnk");//删除原来的桌面快捷键方式
return;
}
//注:如果桌面有现准备创建的快捷键方式,当程序执行创建语句时会修改桌面已有快捷键方式,程序不会出现异常
WshShell shell = new WshShell();
//快捷键方式创建的位置、名称
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut( Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + "上传更新程序.lnk");
shortcut.TargetPath = @Application.StartupPath+"\\auto.AutoTranUpdate.exe"; //目标文件
shortcut.WorkingDirectory = System.Environment.CurrentDirectory;//该属性指定应用程序的工作目录,当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。
shortcut.WindowStyle = 1; //目标应用程序的窗口状态分为普通、最大化、最小化【1,3,7】
shortcut.Description = "自动更新程序"; //描述
shortcut.IconLocation = Application.StartupPath + "\\App.ico"; //快捷方式图标
shortcut.Arguments = "";
shortcut.Hotkey = "CTRL+ALT+F11";
// 快捷键
shortcut.Save(); //必须调用保存快捷才成创建成功
相关文章推荐
- OCX打包成CAB包以及签名发布
- winform绑定快捷键的方法
- C#实现WinForm捕获最小化事件的方法
- WinForm之BindingSource基础操作实例教程
- WinForm相对路径的陷阱
- web下载的ActiveX控件自动更新
- C#采用Winform实现类似Android的Listener
- WinForm自定义控件应用实例
- WinForm实现为TextBox设置水印文字功能
- C#设置WinForm中DataGrid列的方法(列宽/列标题等)
- WinForm实现最小化到系统托盘方法实例详解
- WinForm中的几个实用技巧汇总
- WinForm实现按名称递归查找控件的方法
- Winform实现抓取web页面内容的方法
- WinForm特效之桌面上的遮罩层实现方法
- activex 控件制作成cab包的问题
- WinForm中KeyDown,KeyPress和KeyUp的顺序与区别解析
- WinForm自定义函数FindControl实现按名称查找控件
- 深入分析C#中WinForm控件之Dock顺序调整的详解
- WinForm窗体间传值的方法