C# 创建快捷方式
贴代码
/// <summary>
/// 创建快捷方式
/// </summary>
/// <param name="lnkPath">lnk文件存放路径(快捷方式文件路径:C:\\test.lnk)</param>
/// <param name="exePath">要打开的程序路径:C:\\test.exe</param>
/// <param name="arg">程序启动参数字符串</param>
/// <param name="iconPath">快捷方式图片绝对路径</param>
private void CreateShortcut(string lnkPath, string exePath, string arg = "", string iconPath = null)
{
if (File.Exists(lnkPath))
File.Delete(lnkPath);
dynamic shell = Activator.CreateInstance(Type.GetTypeFromProgID("WScript.Shell"));
var shortcut = shell.CreateShortcut(lnkPath);//创建文件
shortcut.TargetPath = exePath;//exe路径
shortcut.Arguments = arg;// 参数
shortcut.WorkingDirectory = System.IO.Path.GetDirectoryName(exePath);//程序所在文件夹,在快捷方式图标点击右键可以看到此属性
if (iconPath != null)
shortcut.IconLocation = iconPath;
//shortcut.Hotkey = "CTRL+SHIFT+Z";//热键
shortcut.WindowStyle = 1;//窗口
shortcut.Save();
}