首先要添加对 Windows Script Host Object Model的引用
然后使用
1 using IWshRuntimeLibrary;
添加代码:
1 WshShell shell = new WshShell();
2
3 string desktopShortCutPath = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\测试.lnk";
4
5 desktopShortCutPath = System.Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\程序\\ddd\\dadfd.lnk";
6
7 //程序菜单用
8 string ddd = Path.GetDirectoryName(desktopShortCutPath);
9 if (!Directory.Exists(ddd))
10 {
11 Directory.CreateDirectory(ddd);
12 }
13
14 IWshShortcut sc = (IWshShortcut)shell.CreateShortcut(desktopShortCutPath);
15 sc.TargetPath = Application.StartupPath + "\\ShortCut.exe";
16 sc.Description = "测试啦";
17 sc.Save();