CSharp C# Simple Diagnostics.process.start with Exit code
This example starts calc.exe with PsExec.exe and retrieves exit code 0 if closed normally and exit code 1 if process is ended by the task manager.
using System; 
namespace Stuff4 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 
            Console.Clear(); 
            //---------------------------- 
            System.Diagnostics.ProcessStartInfo myProcessInfo = new System.Diagnostics.ProcessStartInfo("PsExec.exe"); 
            myProcessInfo.Arguments = "calc.exe";             
            System.Diagnostics.Process myProcess = System.Diagnostics.Process.Start(myProcessInfo); 
            myProcess.WaitForExit(); 
            Console.WriteLine("myProcess.ExitCode={0}", myProcess.ExitCode); 
            //---------------------------- 
            Console.WriteLine(); 
            Console.WriteLine("done"); 
            Console.ReadLine(); 
        } 
    } 
} 
 | 
No comments:
Post a Comment