How do you create an application shortcut (.lnk file) in C# or using the .NET framework?
The result would be a .lnk file to the specified application or URL.
Open the Windows File Explorer by pressing Windows key + E at the same time. Browse to the folder containing the program you want to use for the shortcut. Right-click the program and select Create Shortcut from the drop-down menu that appears.
It's not as simple as I'd have liked, but there is a great class call ShellLink.cs at vbAccelerator
This code uses interop, but does not rely on WSH.
Using this class, the code to create the shortcut is:
private static void configStep_addShortcutToStartupGroup() { using (ShellLink shortcut = new ShellLink()) { shortcut.Target = Application.ExecutablePath; shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath); shortcut.Description = "My Shorcut Name Here"; shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal; shortcut.Save(STARTUP_SHORTCUT_FILEPATH); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With