我想在桌面上创建一个指向某个 EXE 文件的快捷方式,使用 .NET Framework 3.5 并依赖于官方 Windows API。我怎样才能做到这一点?
最佳答案
具有热键、描述等附加选项
首先,Project > 添加引用> COM > Windows Script Host Object Model。
using IWshRuntimeLibrary;
private void CreateShortcut()
{
object shDesktop = (object)"Desktop";
WshShell shell = new WshShell();
string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Notepad.lnk";
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# - 在桌面上创建快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4897655/