1. 程式人生 > >C# 建立一個資料夾快捷方式

C# 建立一個資料夾快捷方式

IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
//通過該物件的 CreateShortcut 方法來建立 IWshShortcut 介面的例項物件
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(‘快捷方式名稱’);//*.lnk,可以寫寫全路徑名稱,這樣就不用設定WorkingDirectory 屬性
shortcut.TargetPath = linkPath;//快捷方式指向路徑
shortcut.WorkingDirectory = ‘快捷方式存放目錄’;//就是將這個快捷方式放在哪個目錄下,如果在CreateShortcut的時候用的全路徑,這個步驟可以省略
shortcut.WindowStyle = 1;(透過快捷鍵開啟資料夾的時候1.Normal window普通視窗,3.Maximized最大化視窗,7.Minimized最小化)
shortcut.Description = ‘快捷方式描述資訊’;
shortcut.IconLocation = “自定義圖示”
shortcut.Hotkey = "快捷鍵“;//hotkey如shift + A
 shortcut.Save();//儲存