Chasler Chasler - 1 year ago 109
C# Question

Creating application shortcut in a directory

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.

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download