How to create application shortcut programmatically using C#

So someday you might need to create shortcut of or in your application programatically.

Here is how you can do it:

A shortcut is basically a LINK to the original file / executable that will be called when the link / shortcut is clicked.

To create shortcut pro-grammatically, first you need add reference to Windows Script Host Object Model COM library in your project.

Add reference to Windows Script Host Object Model

Next add this using to your class - using IWshRuntimeLibrary;

Next code snippet to create shortcut:

var startupFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var shell = new WshShell();
var shortCutLinkFilePath = Path.Combine(startupFolderPath, @"CreateShortcutSample.lnk");
var windowsApplicationShortcut = (IWshShortcut)shell.CreateShortcut(shortCutLinkFilePath);
windowsApplicationShortcut.Description = "How to create short for application example";
windowsApplicationShortcut.WorkingDirectory = Application.StartupPath;
windowsApplicationShortcut.TargetPath = Application.ExecutablePath;

Using above code, I create shortcut on my user's desktop.

First line gives me the path to the desktop of my user - using Environment.SpecialFolder.Desktop.

Next I create instance of WshShell class and build path for the shortcut I wish to create.

Then add the shortcut path to the WshShell instance and added description, working directory path (to my original application folder), target path (my application path) and saved the shortcut to desktop in final step.

Happy Coding !!