There are some situations in which we need to code to create a short cut of our application especially when user loose the shortcuts created by the application after the setup has been run because some shortcuts also have defines special parameters that are for executable that runs program.

So here is article i am presenting that will show you how to write code in c# that will create shortcut programmatically.

Step 1:

Create a New Windows Form Project.

Step 2:

Drag drop a button control from Toolbox to Form name it btnShortcut and Set text Property to "Create Shortcut "

Step 3:

For creating shortcut you need to reference Windows Script Host Object so follow the steps as below

Step 3a:

8-6-2010 6-36-00 PM.gif

Step 3b:

8-6-2010 6-39-47 PM.gif

Step 4:

Add namespace as below

using IWshRuntimeLibrary;

Step 5:

Now write code in Button's Click event like below

private void btnShortcut_Click(object sender, EventArgs e)

{

WshShellClass shell = new WshShellClass();

IWshShortcut shortcut =     (IWshShortcut)shell.CreateShortcut(@"D:\shotcut.lnk");

shortcut.TargetPath = Application.ExecutablePath;

//shortcut.IconLocation = 'Location of iCon you want to set";

// add Description of Short cut

shortcut.Description = "Any Description here ";

// save it / create

shortcut.Save();

}

Step 6: you are done here is your result

8-6-2010 6-57-23 PM.gif