usingSystem.Runtime.InteropServices;usingiwshruntimelibrary;//Add Reference: COM under Windows Script Host Object Model Public BOOLCreatelnk () {stringApp ="Http://www.cnblogs.com/iack"; stringLocation1 = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Favorites) +"\\iack in Cnblogs.url"; stringLocation2 = System.Environment.GetFolderPath (System.Environment.SpecialFolder.DesktopDirectory) +"\\iack in Cnblogs.url"; stringLocation3 = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Programs) +"\\iack in Cnblogs.url"; Try { //Create a Windows Script Host Shell classIwshshell_class Shell =NewIwshshell_classclass (); //Define the shortcut fileIwshurlshortcut shortcut = Shell. CreateShortcut (Location1) asIwshurlshortcut; Shortcut. TargetPath=app; //Save Itshortcut. Save (); Shortcut= Shell. CreateShortcut (Location2) asIwshurlshortcut; Shortcut. TargetPath=app; //Save Itshortcut. Save (); Shortcut= Shell. CreateShortcut (Location3) asIwshurlshortcut; Shortcut. TargetPath=app; //Save Itshortcut. Save (); return true; } Catch(COMException ex) {Console.WriteLine (ex). Message); return false; } }
If you want to customize the icon for a shortcut link, use the
Using System.Runtime.InteropServices; Using iwshruntimelibrary;//Add Reference: COM under Windows Script Host Object Model public bool Createlnk () {s Tring app = "C:\windows\system32\calc.exe"; String lnklocation = System.Environment.GetFolderPath (System.Environment.SpecialFolder.DesktopDirectory) + "\ \ Calculator. lnk "; try {//Create a Windows Script Host shell class iwshshell_class shell = new IWs Hshell_classclass (); Define the shortcut file Iwshshortcut_class shortcut = Shell. CreateShortcut (lnklocation) as Iwshshortcut_class; Shortcut. TargetPath = app; Shortcut. Description = Lnkdesc; Shortcut. IconLocation = app + ", 0"; Shortcut. Save (); return true; } catch (COMException ex) {Console.WriteLine (ex. Message); return false; } }
The
can implement a custom icon. :