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();//保存快捷方式
}
WinForm桌面快捷方式创建
本文介绍了一种在Windows应用程序中使用WinForm技术创建桌面快捷方式的方法。通过使用IWshRuntimeLibrary库,可以轻松地为应用程序生成桌面快捷图标,并指定了快捷方式的目标路径、工作目录等关键属性。
1005

被折叠的 条评论
为什么被折叠?



