I wantto create a program that will run a batch file (*.bat), and once it is done (it could take a minute) will run another .exe program...
How can i do this???
I need help mostly with running the bat file, and recognizing when it's done running...
Printable View
I wantto create a program that will run a batch file (*.bat), and once it is done (it could take a minute) will run another .exe program...
How can i do this???
I need help mostly with running the bat file, and recognizing when it's done running...
Try using the System.Diagnostics.Process class. You can use it to launch the command prompt with batch file as an argument. You can use the StartInfo property to set the parameters. The Start method starts the process. You can call the WaitToExit function so that the thread is blocked until the process completes or you can subscribe to the Exited event to be notified when the batch file finishes running and process has exited.
You're going to want to take a look at the System.Diagnostics.Process class. Inside of it it has a StartInfo class that you can fill in with executable location data.
Then after this you can run your .exe file in the same way.Code:Process batFile = new Process();
batFile.StartInfo.Filename = "whatever.bat";
batFile.StartInfo.Arguments = "stuff";
batFile.Start();
batFile.WaitForExit(); // this call will block until batFile has finished.
Beaten by nelo by mere minutes!
Let's say I got the pseudo-code and you got the down to the actual implementation :)Quote:
Originally Posted by opedog
Thanks Alot opedog and nelo...
but I have another small question!...
After I ran the batch file, lets say the .exe file could be running already. How can i check this.
If it's running already, i'll just wanna maximize it's window or something of that nature, and if not then load it, of course...
Thanks Again...
Try the Process.GetProcesses() or Process.GetProcessesByName() method. That should give you a start.
Well,
I found the way to fins the process. I do it through GetProcessByName();
but then I couldn't fins the way to maximize it, if im not the one starting the process...
I think I can only do it through Win32APPI's.. or unmanaged code... but im not sure...
Anyway,
Thanks Again!
In order to maximize the window of the .exe, you'd somehow have to match up the Process with the window handle. Unfortunately I'm not sure how to do this. :(
If you can change the source for the executable you want to maximize you might have another way out. You change the target application so that it could receive some kind of message or signal. You could maximise the window in response to that message/signal. I'll let you know if I can work out any of the implementation options. But this is only an option if you can change the target executable. Is that the case?