#region 快捷方式 private static void CreateDesktopLnk() { string DesktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop); if (DesktopPath.ToLower().Equals(Application.StartupPath.ToLower()) == false) CreateDesktopLnkEx(DesktopPath, ShortCutFileName); //string StartupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); //CreateDesktopLnkEx(StartupPath, ShortCutFileName); } private static void CreateDesktopLnkEx(string LnkPath, string LnkFileName) { WshShell shell = new WshShell(); IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(LnkPath + "\\" + LnkFileName); shortcut.TargetPath = Application.ExecutablePath; shortcut.Arguments = ""; shortcut.Description = AppName; shortcut.WorkingDirectory = Application.StartupPath; shortcut.IconLocation = Application.ExecutablePath + ",0"; shortcut.WindowStyle = 1; shortcut.Save(); } #endregion
以前想着如何讓應用開機啓動的時候,有想着去添加註冊表之類的,很是的麻煩,WIN7以上的系統還涉及到管理員權限的問題。其實最方便的實現方法就是直接在系統的「啓動」目錄下創建一個快捷方式。css