標籤:des winform style class blog code
/// <summary> /// 建立捷徑 /// </summary> public class Lnk { /// <summary> /// 建立捷徑的方法 /// </summary> /// <param name="FolderPath">捷徑存放的位置</param> /// <param name="PathLink">指向串連的檔案</param> /// <param name="LnkName">捷徑的檔案</param> /// <param name="LnkNote">捷徑的備忘</param> /// <param name="IconLocationPath">指定捷徑的表徵圖</param> public void CreateShortcutLnk(string FolderPath, string PathLink, string LnkName, string LnkNote, string IconLocationPath) { try { WshShell shell = new WshShell(); IWshShortcut Shortcut = (IWshShortcut)shell.CreateShortcut(FolderPath + "\\" + LnkName + ".lnk"); Shortcut.TargetPath = PathLink; Shortcut.WindowStyle = 1; Shortcut.Description = LnkNote; Shortcut.IconLocation = IconLocationPath; Shortcut.Save(); } catch { throw new Exception("出錯了,捷徑未能建立。"); } } }
Lnk CreateLnk = new MagicLibrary.Shortcuts.Lnk(); CreateLnk.CreateShortcutLnk(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Application.ExecutablePath, "捷徑", "我的軟體", Application.ExecutablePath);