- This topic helps to create shortcut for application exe to the desktop in C#.
- You can create shortcut for application exe or any other application exe to the desktop in C#.
- This example shows how to create our visual studio application exe to the desktop in C#.
- For this topic, you have to add a Button Control to the form and also import a namespace called IWshRuntimeLibrary in C#.
C# – Create shortcut for application exe to the desktop in C#
- C# is an Object Oriented Programming language from Microsoft that mainly combines the computing power of C++ with the programming ease of Visual Basic.
- C# is mainly based on C++.
- The most recent version is C#4.0.
- C# language is simple, modern, general-purpose, object-oriented language.
- Timer is a control available in Visual C#.NET
To import IWshRuntimeLibrary class do the following steps
1) Right click on the solution explorer and select add reference
2) Select COM tab and select Windows Script Host object Model and click OK
IWshRuntimeLibrary - Create shortcut for application exe to the desktop in C#
- IWshRuntimeLibrary.dll is an automatically generated wrapper DLL for wshom.ocx.
- You cannot redistribute wshom.ocx but can freely redistribute wrapper DLLs as required by your app to run.
Create shortcut for application exe to the desktop in C# – Complete Code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
using System; using Microsoft.VisualBasic; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using IWshRuntimeLibrary; namespace WindowsFormsApplication1 { public partial class Form1 : Form { bool myBool = false; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { WshShellClass shell = new WshShellClass(); IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(@"C:\Appshotcut.lnk"); shortcut.TargetPath = Application.ExecutablePath; //shortcut.IconLocation = 'Location of iCon you want to set" // add Description of ShortCut file shortcut.Description = "Any Description here "; // Save shortcut file. shortcut.Save(); } } } |
Create shortcut for application exe to the desktop in C#






