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)