GettingStarted
GettingStarted

Reputation: 7605

Process.Start any way to delay the closing of the window?

    public void ProcessStartAsAdmin(string command)
    {
        Process myProcess = new Process();
        myProcess.StartInfo.FileName = @"C:\application.EXE";
        myProcess.StartInfo.Verb = @"runas";
        myProcess.StartInfo.Arguments = command;
        myProcess.Start();
    }

The Dos box closes very quickly and I can't tell if there are any errors or if it completed successfully. Is there anyway to keep the window alive until I manually close it?

Upvotes: 1

Views: 982

Answers (1)

Servy
Servy

Reputation: 203835

Rather than running the application, start up a new shell (cmd.exe) and have that shell run the application by passing the command to run this application to it. You can then exit the shell whenever you want using its "exit" command.

The other comparable solution is to create a batch script that just executes this command and then pauses for user input asking it to close. Your program would then execute that script, instead of the application directly.

The other option is just to redirect the standard output to your application, instead of having it printed to the console, allowing you to do whatever you want with the output well after the program finishes execution.

Upvotes: 4

Related Questions