這篇文章主要介紹了C#實現(xiàn)在啟動目錄創(chuàng)建快捷方式的方法,涉及C#快捷方式的創(chuàng)建技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了C#實現(xiàn)在啟動目錄創(chuàng)建快捷方式的方法。分享給大家供大家參考。具體如下:
添加引用,選擇 COM 選項卡并選擇 Windows Script Host Object Model
- /// <summary>
- /// 將文件放到啟動文件夾中開機(jī)啟動
- /// </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 = "";//參數(shù)
- shortcut.Description = description;//描述
- shortcut.WorkingDirectory = System.IO.Path.GetDirectoryName(setupPath);//程序所在目錄
- shortcut.IconLocation = setupPath;//圖標(biāo)
- shortcut.WindowStyle = 1;
- shortcut.Save();
- }
- catch (Exception ex)
- {
- System.Windows.Forms.MessageBox.Show(ex.Message, "友情提示");
- }
- finally
- {
- shell = null;
- shortcut = null;
- }
- }
希望本文所述對大家的C#程序設(shè)計有所幫助。
新聞熱點
疑難解答