1, 项目中添加一个引用。Project > Add Reference > COM > Windows Script Host Object Model.
示例代码:
WshShell shell = new WshShell();
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string shotcutName = "alex.lnk";
string shortcutAddress = Path.Combine(desktopPath, shotcutName);
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
shortcut.Description = "New shortcut for a Notepad";
//shortcut.Hotkey = "Ctrl+Shift+N";
shortcut.TargetPath = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\notepad.exe";
shortcut.Save();
本文介绍了如何在C#项目中通过引用Windows Script Host Object Model来创建桌面快捷方式。详细步骤包括在项目中添加COM引用,并提供了相关的示例代码。

3188

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



