"Reprint" c#.net Create a page shortcut

Source: Internet
Author: User

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. :

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.