C#實現(xiàn)在啟動目錄創(chuàng)建快捷方式的方法
更新時間:2015年09月07日 12:58:20 作者:我心依舊
這篇文章主要介紹了C#實現(xiàn)在啟動目錄創(chuàng)建快捷方式的方法,涉及C#快捷方式的創(chuàng)建技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了C#實現(xiàn)在啟動目錄創(chuàng)建快捷方式的方法。分享給大家供大家參考。具體如下:
添加引用,選擇 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 = "";//參數(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è)計有所幫助。
相關(guān)文章
C#如何使用DateTime.Now.AddDays方法獲取任一天的信息
使用DateTime.Now屬性可以得到當(dāng)前的日期信息,此時調(diào)用ToString方法,并在該方法中添加指定的格式化字符串,可以按照要求輸出當(dāng)前日期的信息,本文介紹C#使用DateTime.Now.AddDays方法獲取任一天的信息,感興趣的朋友一起看看吧2024-01-01

