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:
Step
3b:
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