How to get an exit code from an application. Example: I call: System.Diagnostic.Start("regsvr32", "mydll.dll"); How to get an exit code from regsvr32?
And how to write an application which returns an exit code (like regsvr32). Thanks.
I'am using .NET 4.0 & C#.
This is actually two separate questions, but... The exit code is the value returned from the program's Main function. So:
public static int Main()
{
    // code
    return 0;
}
Will return an exit code of 0. Unless the preceding // code does something different.
Use the Process' ExitCode property to get this value from the application to execute.
0 is typically returned when the program succeeds. Anything else is a failure but this is a matter of interpretation.
Something like this should be sufficient.
private int CallSomething()
{
    using ( var p = new Process() )
    {
        p.StartInfo = new ProcessStartInfo("RegSvr32");
        p.Start();
        p.WaitForExit();
        return p.ExitCode;
    }
}
p.ExitCode is the exit code of the called process.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With