Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 591
Charley Rathkopf Avatar asked Oct 24 '08 16:10

Charley Rathkopf


People also ask

How do I create a shortcut in Explorer?

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.


1 Answers

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);     } } 
like image 82
Charley Rathkopf Avatar answered Oct 13 '22 15:10

Charley Rathkopf