Home >Backend Development >C++ >How to Create Desktop Shortcuts with .NET Framework 3.5 and the Windows API?
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:
<code class="language-csharp">using IWshRuntimeLibrary;</code>
<code class="language-csharp">private void CreateShortcut() { object shDesktop = (object)"Desktop"; WshShell shell = new WshShell(); string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Notepad.lnk"; }</code>
<code class="language-csharp"> IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);</code>
<code class="language-csharp"> shortcut.Description = "记事本的新快捷方式"; shortcut.Hotkey = "Ctrl+Shift+N"; shortcut.TargetPath = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\notepad.exe";</code>
<code class="language-csharp"> shortcut.Save();</code>
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!