How to use C # to manipulate shortcuts (get shortcut properties, create shortcuts)

Source: Internet
Author: User

A technique is needed in recent projects: using C # to manipulate shortcuts, including creation and reading. Now tidy up the realization way, share to everybody.

The first step is to create a project

No nonsense, skip.

The second step refers to COM components

Right-click "References", "Add References", select "COM Components", locate "Windows Script Host Object Model", and then OK.

The third step is to write the code that creates the shortcut

Create a shortcut//declaring an Action objectIwshruntimelibrary.wshshell Shell =NewIwshruntimelibrary.wshshellclass ();//Create a shortcutIwshruntimelibrary.iwshshortcut shortcut = (iwshruntimelibrary.iwshshortcut) shell. CreateShortcut ("C:\\yeaicc.lnk");//The associated programShortcut. TargetPath ="notepad.exe";//ParametersShortcut. Arguments ="C:\\yeaicc.txt";//shortcut description, mouse on the shortcut will be displayed OhShortcut. Description ="my shortcut--yeaicc";//Global HotkeyShortcut. Hotkey ="Ctrl+shift+n";//set the icon for the shortcut, here is the program icon, if you want to specify an ICO file, then write the path. Shortcut. IconLocation ="notepad.exe, 0";//save it and create it successfully. Shortcut. Save ();

Fourth Step read Shortcut properties

New= (iwshruntimelibrary.iwshshortcut) shell. CreateShortcut ("c:\\yeaicc.lnk"); // Pro, according to the code you just created, what attributes would you like to get? MessageBox.Show (ws. Description);

================================ Split Line ============================================

C # Create a shortcut The following code can run normally under 2.0,3.0,3.5, with an error in 4.0.

Do not know that for the guy knows to create a shortcut under 4.0.

Select the COM tab and select Windows Script Host Object Model
usingiwshruntimelibrary;namespaceconsoleapplication1{classProgram {Static voidMain (string[] args) {            stringDesktopPath = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Desktop);//Get the Desktop folderWshShell Shell=NewWshShell (); Iwshshortcut Shortcut= (iwshshortcut) shell. CreateShortcut (DesktopPath +"\ \ Automatically create +.lnk"); Shortcut. TargetPath=@"%homedrive%/program files\internet Explorer\iexplore. EXE"; Shortcut. Arguments="http://www.baidu.com";//Parametersshortcut. Description="Quick links to Web sites"; Shortcut. WorkingDirectory="e:\\publish Web Site\\clcs";//The folder where the program is located, right click on the shortcut icon to see this propertyshortcut. IconLocation=@"%homedrive%/program files\internet Explorer\iexplore. EXE, 0";//iconsshortcut. Hotkey="ctrl+shift+z";//Hotkeyshortcut. WindowStyle=1; Shortcut.        Save (); }    }}

How to use C # to manipulate shortcuts (get shortcut properties, create shortcuts)

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.