i unable send commands powershell console after open c# application. have tried other ways have commented out @ bottom of code show have tried. here code using below:
using system; using system.windows.forms; using system.management.automation; system.diagnostics.process cmdprocess = new system.diagnostics.process(); var startprocessinfo = new system.diagnostics.processstartinfo(); startprocessinfo.filename = @"c:\windows\syswow64\windowspowershell\v1.0\powershell.exe"; startprocessinfo.verb = "runas"; cmdprocess.startinfo = startprocessinfo; cmdprocess.start(); startprocessinfo.arguments = @"c:\users\user\desktop\test.ps1"; cmdprocess.waitforexit(); //console.writeline("@c:\\users\\user\\desktop\\test.ps1"); //streamwriter sw = cmdprocess.standardinput; //streamreader sr = cmdprocess.standardoutput; //sw.writeline(@"c:\users\user\desktop\test.ps1"); //startprocessinfo.arguments = @".\test.ps1"; //system.diagnostics.process.start(startprocessinfo);
@chrisdent suggested solution.
however, error code is, have set startinfo
before starting powershell. try this:
system.diagnostics.process cmdprocess = new system.diagnostics.process(); var startprocessinfo = new system.diagnostics.processstartinfo(); startprocessinfo.filename = @"c:\windows\syswow64\windowspowershell\v1.0\powershell.exe"; startprocessinfo.verb = "runas"; startprocessinfo.arguments = @"c:\users\user\desktop\test.ps1"; cmdprocess.startinfo = startprocessinfo; cmdprocess.start(); cmdprocess.waitforexit();
Comments
Post a Comment