C # Create a file shortcut

zhaozj2021-02-16  85

C # Create a file shortcut

Www.wenhui.org 11/5/2002 Csharp vs Java

You can use Interopement to introduce "Windows Script Host Object Model" COM Library in your project. Then run the following code: using System; using System.Runtime.InteropServices; using IWshRuntimeLibrary; namespace CreateShortcutCOM {/// /// This class creates a shortcut with COM interoperability /// class ShortcutDemo {[STAThread] static void Main (string [] args) {// get the app path and filename string app = environments.currentdirectory @ "/ createshortcutcom.exe";

try {// Create a Windows Script Host Shell class IWshShell_Class shell = new IWshShell_ClassClass (); // Define the shortcut file IWshShortcut_Class shortcut = shell.CreateShortcut (app ".lnk") as IWshShortcut_Class; // Set all its properties shortcut. Description = "smortcut.targetpath = app; shortcut.iconlocation = app ", 0 "; // Save it shortcut.save (); Catch (comexception ex) {Console.Writeline (EX .MEsSAGE);}}}}

转载请注明原文地址:https://www.9cbs.com/read-15212.html

New Post(0)