Yesterday, I just came accross how to create new and read shorcuts information when my colleague asked for helps on how to read back the information from created shorcuts.
Create new shortcut
// Create a new instance of WshShellClass
WshShell = new WshShellClass();
// Create the shortcut
IWshRuntimeLibrary.IWshShortcut MyShortcut;
// Choose the path for the shortcut
MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(@"C:\MyShortcut.lnk");
// Where the shortcut should point to
MyShortcut.TargetPath = Application.ExecutablePath;
// Description for the shortcut
MyShortcut.Description = "Launch My Application";
// Location for the shortcut's icon
MyShortcut.IconLocation = Application.StartupPath + @"\App.ico";
// Create the shortcut at the given path
MyShortcut.Save();
Read shortcut information
// Create a new instance of WshShellClass
WshShell = new WshShellClass();
// Create the shortcut
WshShortcut MyShortcut;
// Assign the shortcut path
MyShortcut = (WshShortcut)WshShell.CreateShortcut(@"C:\MyShortcut.lnk");
// Get TargetPath of the shortcut
string tragetPath = MyShortcut.TargetPath;
// Get description of the shortcut
string description = MyShortcut.Description;
// Get Location of the shortcut's icon
string IconLocation = MyShortcut.IconLocation;
You must add Interop.IWshRuntimeLibrary.dll as references before you can use the above code.
Download Interop.IWshRuntimeLibrary.dll or install Microsoft Interop Forms Toolkit 2.0.
Hope it helps you.