C#操作快捷方式(获取快捷方式属性、创建快捷方式)
生活随笔
收集整理的這篇文章主要介紹了
C#操作快捷方式(获取快捷方式属性、创建快捷方式)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
第一步? 創建一個項目
無需廢話,跳過。
第二步? 引用COM組件
右鍵“引用”,“添加引用”,選擇“COM組件”,找到“Windows Script Host Object Model”,然后確定。
第三步? 編寫創建快捷方式的代碼
1 // 聲明操作對象2 IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass();3 // 創建一個快捷方式4 IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut("c:\\yeaicc.lnk");5 // 關聯的程序6 shortcut.TargetPath = "notepad.exe";7 // 參數8 shortcut.Arguments = "c:\\yeaicc.txt";9 // 快捷方式描述,鼠標放到快捷方式上會顯示出來哦 10 shortcut.Description = "我的快捷方式--yeaicc"; 11 // 全局熱鍵 12 shortcut.Hotkey = "CTRL+SHIFT+N"; 13 // 設置快捷方式的圖標,這里是取程序圖標,如果希望指定一個ico文件,那么請寫路徑。 14 shortcut.IconLocation = "notepad.exe, 0"; 15 // 保存,創建就成功了。 16 shortcut.Save();第四步? 讀取快捷方式屬性
1 IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass(); 2 IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut("c:\\yeaicc.lnk"); 3 // 親,根據剛剛創建時的代碼,你想獲取什么屬性? 4 MessageBox.Show(ws.Description);總結
以上是生活随笔為你收集整理的C#操作快捷方式(获取快捷方式属性、创建快捷方式)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 简述单机,集群,分布式架构区别及联系
- 下一篇: C#如何判断程序调用的exe已结束