Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Process.Start(), How can I keep cmd prompt open when the /K argument doesn't work? [duplicate]

Tags:

c#

cmd

Possible Duplicate:
Any way to keep an external command window open during a Process.Start(..)?

I've seen this post before but those solutions don't work for me for some reason. With Process.Start(), How can I keep cmd prompt open when the /K argument doesn't work? There's also no "WaitForExit" method available.

ProcessStartInfo processInfo = new ProcessStartInfo("cmd.exe", "/K " + "C:\\Windows\\System32\\" + "takeown.exe");
processInfo.Verb = "runas";
processInfo.Arguments = "/F \"C:\\Program Files(x86)\\Borland\" /R /D Y";
Process.Start(processInfo);

What I want to see is if the process processed successfully.

Thanks

like image 921
JimDel Avatar asked Dec 21 '22 12:12

JimDel


2 Answers

You can wait for the process to finish before continuing:

var process = Process.Start(processInfo);
process.WaitForExit();
if (process.ExitCode != 0) {
    // Handle failure...
}
like image 151
Cameron Avatar answered Dec 23 '22 02:12

Cameron


Try this:

ProcessStartInfo processInfo = new ProcessStartInfo("cmd.exe");
processInfo.Verb = "runas";
processInfo.Arguments = "/K C:\\Windows\\System32\takeown.exe /F \"C:\\Program Files(x86)\\Borland\" /R /D Y";
Process.Start(processInfo);
like image 23
Chooko Avatar answered Dec 23 '22 02:12

Chooko