Click here to Skip to main content
15,893,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want a certain exe file to run on a certain command in my program and only once that exe file closes (does what it needs to do) then carry on with my program's script. How do I do this?
Posted
Updated 30-Jan-12 21:05pm
v2

See my answer here
how to execute .jar files in c#[^]

Thanks
--RA
 
Share this answer
 
C#
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        public static void Main()
        {
            Process myProcess = new Process();

            try
            {
                myProcess.StartInfo.UseShellExecute = false;
                // You can start any process, HelloWorld is a do-nothing example.
                myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.Start();
                // This code assumes the process you are starting will terminate itself.
                // Given that is is started without a window so you cannot terminate it
                // on the desktop, it must terminate itself or you can do it programmatically
                // from this application using the Kill method.
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}
 
Share this answer
 
Comments
Dalek Dave 31-Jan-12 3:59am    
Good Answer.
System.Diagnostics.Process.Start(exefilepath);
 
Share this answer
 
also add:

C#
myProcess.WaitForExit();
//this makes the program wait for the external program to terminate before carrying on with its own code
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900