|
-
April 17th, 2008, 07:51 AM
#1
[RESOLVED] Running a batch (*.bat) file...?
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...
Rate this post if you found it useful!
10X, gilly914
-
April 17th, 2008, 08:07 AM
#2
Re: Running a batch (*.bat) file...?
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.
-
April 17th, 2008, 08:10 AM
#3
Re: Running a batch (*.bat) file...?
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.
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.
Then after this you can run your .exe file in the same way.
-
April 17th, 2008, 08:11 AM
#4
Re: Running a batch (*.bat) file...?
Beaten by nelo by mere minutes!
-
April 17th, 2008, 08:30 AM
#5
Re: Running a batch (*.bat) file...?
 Originally Posted by opedog
Beaten by nelo by mere minutes!
Let's say I got the pseudo-code and you got the down to the actual implementation
-
April 19th, 2008, 05:15 AM
#6
Re: Running a batch (*.bat) file...?
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...
Rate this post if you found it useful!
10X, gilly914
-
April 19th, 2008, 02:58 PM
#7
Re: Running a batch (*.bat) file...?
Try the Process.GetProcesses() or Process.GetProcessesByName() method. That should give you a start.
-
April 19th, 2008, 08:03 PM
#8
Re: Running a batch (*.bat) file...?
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!
Rate this post if you found it useful!
10X, gilly914
-
April 21st, 2008, 07:20 AM
#9
Re: [RESOLVED] Running a batch (*.bat) file...?
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.
-
April 21st, 2008, 07:33 AM
#10
Re: [RESOLVED] Running a batch (*.bat) file...?
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|