创建桌面快捷方式
程序员文章站
2022-03-31 21:37:18
...
public class DeskLnk
{
/// <summary>
/// 创建桌面快捷方式
/// </summary>
/// <param name="lnk">快捷方式名称,无后缀名</param>
/// <param name="des">快捷方式描述</param>
/// <returns>没有内容返回</returns>
public void Create(string lnk,string des)
{
string deskTopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop)
+ "\\" + lnk + ".lnk";
string exePath = Application.ExecutablePath;
WshShell shell0 = new WshShell();
IWshShortcut shortcut0 = (IWshShortcut)shell0.CreateShortcut(deskTopPath);
if (System.IO.File.Exists(deskTopPath) && exePath != shortcut0.TargetPath)
{
System.IO.File.Delete(deskTopPath);
}
if (!System.IO.File.Exists(deskTopPath)) //
{
WshShell shell = new WshShell();
//快捷键方式创建的位置、名称
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(deskTopPath);
shortcut.TargetPath = exePath;//目标文件
shortcut.WorkingDirectory = System.Environment.CurrentDirectory;//该属性指定应用程序的工作目录,
//当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。
shortcut.WindowStyle = 1; //目标应用程序的窗口状态分为普通、最大化、最小化【1,3,7】
shortcut.Description = des; //描述
shortcut.IconLocation = exePath + ",0"; //快捷方式图标
shortcut.Arguments = "";
// shortcut.Hotkey = "CTRL+ALT+F11"; // 快捷键
shortcut.Save(); //必须调用保存快捷才成创建成功 }
}
}
}
上一篇: 创建桌面快捷方式
下一篇: 具体介绍HTML5表单新增属性