winform生成桌面快捷方式
注意设置起始位置,不然运行会报错!
/// <summary>
/// 生成桌面快捷方式
/// </summary>
private void CreateShortcutOnDesktop()
{
string shortcutPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "快捷方式名称.lnk");
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath);//创建快捷方式对象
shortcut.TargetPath = "C:\\***\\****.exe";//指定目标路径
shortcut.WorkingDirectory = Path.GetDirectoryName("C:\\***");//设置起始位置
shortcut.Description = "无";//设置备注
shortcut.IconLocation = "C:\\***\\****.exe";//设置图标路径
shortcut.Save();//保存快捷方式
}