c# - I cant get the CMD outputs to display in my textbox. -


since local user group management doesnt seem can query in c#, figured down , dirty version of trying accomplish , need advice best practices.

the goal: essentially, need determine if current local user's password set expire , display result in textbox. have written text search dont mind there data sitting on output since distill data down boolean check 1 string.

the problem: check out code below. reason error codes come through cmd fine, however, output not display in textbox2.

            string username = system.security.principal.windowsidentity.getcurrent().name.split('\\').last(); ;             user.text = username;              process cmd = new process();             cmd.startinfo.filename = "cmd.exe";             cmd.startinfo.arguments = "/c net user";             cmd.startinfo.useshellexecute = false;             cmd.startinfo.redirectstandardoutput = true;             cmd.startinfo.redirectstandarderror = true;             cmd.start();             //* read output (or error)             string output = cmd.standardoutput.readtoend();             textbox2.text = output;             string err = cmd.standarderror.readtoend();             textbox2.text = err;             cmd.waitforexit(); 

first you're putting output variable textbox2.text, replacing textbox2.text err , believe you're getting nothing err variable, that's why textbox2 not displaying you're expecting.

try run snippet below check how output , err variable getting:

string username = system.security.principal.windowsidentity.getcurrent().name.split('\\').last(); ;             string text = username;              process cmd = new process();             cmd.startinfo.filename = "cmd.exe";             cmd.startinfo.arguments = "/c net user";             cmd.startinfo.useshellexecute = false;             cmd.startinfo.redirectstandardoutput = true;             cmd.startinfo.redirectstandarderror = true;             cmd.start();             //* read output (or error)             string output = cmd.standardoutput.readtoend();              string err = cmd.standarderror.readtoend();              console.writeline("output: "+output );             console.writeline("err: "+err);             cmd.waitforexit();             console.readkey(); 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -