C # create a shortcut
You must first reference the COM component InterOP. iwshruntimelibrary. dll, as shown in figure
Code
Private void createlnk (string lnkpath) {If (! System. io. file. exists (lnkpath) {iwshruntimelibrary. wshshell shell = new iwshruntimelibrary. wshshell (); iwshruntimelibrary. iwshshortcut cut = (iwshruntimelibrary. iwshshortcut) Shell. createshortcut (lnkpath); shortcut cut. targetpath = application. executablepath; export cut. windowstyle = 1; shortcut cut. description = application. productname + application. productversion; shortcut. iconlocation = application. executablepath; export cut. workingdirectory = application. startuppath; shortcut. save ();}}
Get desktop path
String lnkpath = system. environment. getfolderpath (environment. specialfolder. desktop) + "\" + application. productname + ". lnk ";
Get the Startup Folder path
String lnkpath = system. environment. getfolderpath (environment. specialfolder. startup) + "\" + application. productname + ". lnk ";
Enable the Registry
The operation is to add HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run to the Registry.ProgramPath
Registrykey key = registry. localmachine; Key = key. opensubkey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run", true); key. setvalue (application. productname, application. executablepath );
Note that this method is tested in win7 and an error is reported!System. unauthorizedaccessexception: attempts to perform unauthorized operations.
Create URL shortcuts
String destination dir = system. environment. getfolderpath (environment. specialfolder. desktop); Using (streamwriter writer = new streamwriter (export dir + "\ AAAA. URL ") {writer. writeline ("[internetshortcut]"); writer. writeline ("url = http://www.163.com/"); writer. flush ();}
Example download: http://files.cnblogs.com/zjfree/linkTo.rar
Running Environment: win2003 + vs2005