CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 2004
    Location
    Holy Land
    Posts
    306

    [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

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    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.

  3. #3
    Join Date
    Mar 2008
    Location
    Atlanta, GA
    Posts
    49

    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.

  4. #4
    Join Date
    Mar 2008
    Location
    Atlanta, GA
    Posts
    49

    Re: Running a batch (*.bat) file...?

    Beaten by nelo by mere minutes!

  5. #5
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Running a batch (*.bat) file...?

    Quote 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

  6. #6
    Join Date
    Jul 2004
    Location
    Holy Land
    Posts
    306

    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

  7. #7
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Running a batch (*.bat) file...?

    Try the Process.GetProcesses() or Process.GetProcessesByName() method. That should give you a start.

  8. #8
    Join Date
    Jul 2004
    Location
    Holy Land
    Posts
    306

    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

  9. #9
    Join Date
    Mar 2008
    Location
    Atlanta, GA
    Posts
    49

    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.

  10. #10
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    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
  •  





Click Here to Expand Forum to Full Width

Featured