Registrykey key = registry. localmachine. opensubkey ("SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run", true); // open the registry subkey. setvalue (program name, program path); or wshshell shell = new wshshell (); iwshshortcut shortcut = (iwshshortcut) Shell. createshortcut (shortcutpath );
Public void setautorun (string filename, bool isautorun) {registrykey Reg = NULL; try {If (! System. Io. file. exists (filename) throw new exception ("this file does not exist! "); String name = filename. substring (filename. lastindexof (@ "\") + 1); Reg = registry. localmachine. opensubkey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run", true); If (REG = NULL) reg = registry. localmachine. createsubkey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run"); If (isautorun) reg. setvalue (name, filename); else Reg. setvalue (name, false); lbl_autorunerr.visible = false;} catch {lbl_aut Orunerr. Visible = true; // throw new exception (ex. tostring ();} finally {If (Reg! = NULL) reg. Close ();}}