Running CMD as administrator with an argument from C# -
i want run cmd.exe
administrator arguments c# in order prevent uac popup. necessary in order use automated installation process. command passing in path installation file (.exe) /q
quiet installation.
when run code, there cmd popup, runs if didn't execute anything.
public static string executecommandasadmin(string command) { processstartinfo procstartinfo = new processstartinfo() { redirectstandarderror = true, redirectstandardoutput = true, useshellexecute = false, createnowindow = true, filename = "runas.exe", arguments = "/user:administrator cmd /k " + command }; using (process proc = new process()) { proc.startinfo = procstartinfo; proc.start(); string output = proc.standardoutput.readtoend(); if (string.isnullorempty(output)) output = proc.standarderror.readtoend(); return output; } }
there @ least 1 problem command, line:
arguments = "/user:administrator cmd /k " + command
should be:
arguments = "/user:administrator \"cmd /k " + command + "\""
also, won't work automated process, because ask administrator's password in windows vista , newer not known.
Comments
Post a Comment