c# - How to run cmd command under administrator rights? -
this question has answer here:
how can run below command under administrator approval in visual c#? need hide console windows while running console.
thanks.
private void button5_click(object sender, eventargs e) { process process = new process(); processstartinfo startinfo = new processstartinfo(); startinfo.filename = "cmd.exe"; startinfo.arguments = "/c netsh wlan set hostednetwork mode=allow ssid=hotspot key=12345678"; startinfo.verb = "runas"; startinfo.useshellexecute = true; startinfo.windowstyle = processwindowstyle.hidden; process.startinfo = startinfo; process.start(); process wifistart = new process(); processstartinfo wifistartinfo = new processstartinfo(); wifistartinfo.filename = "netsh.exe"; wifistartinfo.arguments = "/c wlan start hostednetwork"; wifistartinfo.verb = "runas"; wifistartinfo.useshellexecute = true; wifistartinfo.windowstyle = processwindowstyle.hidden; process.startinfo = wifistartinfo; wifistart.start(); }
process.start(new processstartinfo { filename = "netsh", arguments = "wlan set hostednetwork mode=allow ssid=hotspot key=12345678", verb = "runas", useshellexecute = true, windowstyle = processwindowstyle.hidden });
this starts process using "runas" verb, makes shell try execute in elevated privileges mode. need shell involved in in first place, hence useshellexecute = true
value.
the last property tells shell hide new process' window, i'm not sure work console program.
Comments
Post a Comment