1,引用Com组件:Windows Script Host Object Model。
2,获取开始目录路径、桌面路径,并创建相应文件夹。
//获取当前开始目录,桌面
//当前值为:C:\Users\admin\AppData\Roaming\Microsoft\Windows\Start Menu
//实际需要的路径是:C:\Users\admin\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\百度网盘\卸载百度网盘.lnk
string startMenu = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
//设置在开始目录中的保存位置
string startMenuInkDir = System.IO.Path.Combine(startMenu, "Programs", "哆啦A梦奇幻之旅");
if (!System.IO.Directory.Exists(startMenuInkDir))
{
System.IO.Directory.CreateDirectory(startMenuInkDir);
}
string startMenuInkPath = System.IO.Path.Combine(startMenuInkDir, "多啦A梦.lnk");
string deskTop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string deskTopInkPath = System.IO.Path.Combine(deskTop, "哆啦A梦.lnk");
3,创建快捷方式:
//创建位于StartMenu中的快捷方式
IWshRuntimeLibrary.IWshShortcut startMenuShortCut = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(startMenuInkPath);
startMenuShortCut.TargetPath = Application.ExecutablePath;
startMenuShortCut.Description = "我的哆啦A梦奇妙幻想";
startMenuShortCut.IconLocation = System.IO.Path.GetFullPath("../../favicon.ico");
startMenuShortCut.Save();
//创建位于桌面的快捷方式
IWshRuntimeLibrary.IWshShortcut deskShortCut = wsh.CreateShortcut(deskTopInkPath);
deskShortCut.TargetPath = Application.ExecutablePath;
deskShortCut.Description = "机器猫与大熊";
deskShortCut.IconLocation = System.IO.Path.GetFullPath("../../favicon.ico");
deskShortCut.Save();