C#完成在啟動目次創立快捷方法的辦法。本站提示廣大學習愛好者:(C#完成在啟動目次創立快捷方法的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#完成在啟動目次創立快捷方法的辦法正文
本文實例講述了C#完成在啟動目次創立快捷方法的辦法。分享給年夜家供年夜家參考。詳細以下:
添加援用,選擇 COM 選項卡並選擇 Windows Script Host Object Model
/// <summary> /// 將文件放到啟動文件夾中開機啟動 /// </summary> /// <param name="setupPath">啟動法式</param> /// <param name="linkname">快捷方法稱號</param> /// <param name="description">描寫</param> public void SetSetupWindowOpenRun(string setupPath, string linkname, string description) { string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + linkname + ".lnk"; if (System.IO.File.Exists(desktop)) System.IO.File.Delete(desktop); IWshRuntimeLibrary.WshShell shell; IWshRuntimeLibrary.IWshShortcut shortcut; try { shell = new IWshRuntimeLibrary.WshShell(); shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(desktop); shortcut.TargetPath = setupPath;//法式途徑 shortcut.Arguments = "";//參數 shortcut.Description = description;//描寫 shortcut.WorkingDirectory = System.IO.Path.GetDirectoryName(setupPath);//法式地點目次 shortcut.IconLocation = setupPath;//圖標 shortcut.WindowStyle = 1; shortcut.Save(); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "友誼提醒"); } finally { shell = null; shortcut = null; } }
願望本文所述對年夜家的C#法式設計有所贊助。