Create desktop shortcuts using .NET Framework 3.5 and Windows API
Question: How to create a desktop shortcut pointing to an EXE file using .NET Framework 3.5 and the official Windows API?
Answer:
To create a desktop shortcut with additional options such as hotkeys and description, follow these steps:
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 = "记事本的新快捷方式"; shortcut.Hotkey = "Ctrl+Shift+N"; shortcut.TargetPath = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\notepad.exe";
shortcut.Save();
By following these steps, you can programmatically create a desktop shortcut with the desired properties using the .NET Framework 3.5 and Windows API.
The above is the detailed content of How to Create Desktop Shortcuts with .NET Framework 3.5 and the Windows API?. For more information, please follow other related articles on the PHP Chinese website!