Start a program and wait its termination

August 20, 2010 at 07:32:33
Specs: Windows 7 / 64 bit, Q9550 / 4 Gig
Hey there,

I need your valuable help once more. I am making a batch script where in a point of the script I need to start an exe, wait the program to finish and then continue executing the rest script commands. Until now the only working method I've found is by checking periodically if program runs.

However I need something like START " " /WAIT command. Although I've found that this command is what I am looking for, it actually does not work for me. Batch just starts exe and immediately continues executing the rest script without waiting as excepted. That is the way I use it:

....

START "mystart" /WAIT thisexe.exe

....

Have also in mind that since this script is for a game mod, it is needed to be run in any of XP, Vista, Win7.

Thank you.


See More: Start a program and wait its termination

Report •

#1
August 20, 2010 at 10:10:11
That should work, unless thisexe.exe runs some other executable, then terminates before its child.

I'd probably use VBScript and WMI to track the process tree, and go from there.


Report •

#2
August 20, 2010 at 12:42:43
It is a game file (Napoleon.exe for Napoleon Total War). In task manager/processes it is appeared as Napoleon.exe *32 as long as game is running. Is your guess confirmed after that? If yes, can you give me a clew where/how to start following your suggestions? The only thing I know is that VBscript is another scripting language...

One last question, please, if I use the first way

tasklist /FI "IMAGENAME eq thisexe.exe" 2>NUL | find /I /N "thisexe.exe">NUL
if "%ERRORLEVEL%"=="0" do something

and if I assign to check every 15 or 30 sec., will this frequent check has any unpleasant effect to PC performance?

Thanks a lot for support, I really appreciate!


Report •

#3
August 22, 2010 at 06:51:35
Yeah, I think I'm going to have to see the relevant process tree before I try to pretend I know what's going on. I've started, and waited on, 32-bit programs on my Win x64 environments.

Report •

Related Solutions

#4
August 22, 2010 at 10:39:09
Thanks for reply, I'll wait further news.

Report •

#5
August 22, 2010 at 11:06:21
No, no, no. This is the part where you download something that shows you the process tree. I suggest Process Explorer.

Report •

#6
August 22, 2010 at 14:08:52
The Napolen.exe is appeared under Steam tree in processes and under that the file GameOverlayUi.exe. I checked in the net and the later file has rather to do with friends contacts of Steam. The strange thing is that I tried with different applications like CClean, Firefox, etc. and in all cases the /wait never worked.

So let me ask again, if I use a command that checks every few secs if the game is running will affect the performance? It is a tiny work but I want to be sure.

Thank you.


Report •

#7
August 22, 2010 at 14:28:55
It's more work to poll the process list than to have the kernel wake you up when the application exits, yes.

Report •

#8
August 22, 2010 at 15:32:34
O.K. I'll try to solve the wait problem.

Thanks a lot for your help!


Report •

#9
August 22, 2010 at 16:00:59
You don't by chance have an anti-virus active, do you? That might be causing your issue.

Report •

#10
August 22, 2010 at 16:45:17
I disabled avast with no lack.

But now I am closer than ever. I have to run it as admin in order to work (sorry I didn't think of it earlier). But another strange problem has been appeared. Tested on applications it works fine (e.g. CClean). But with the game there is this strange behaviour: If I execute batch as admin it says windows cannot find the exe file. But if I execute it normally, it starts the game without /wait parameter working (the story of my life lately...). It is the same batch and I launch it from the very same location (exe's folder)!!


Report •

#11
August 24, 2010 at 05:54:05
More tests to find out that the problem is that the game is launched through Steam. In normal game /w parameter work fine.

Some more infos:

I've found a Steam's name for Napoleon.exe that is in url form: steam://rungameid/34030. So I change my script to:

START " " /w "steam://rungameid/34030"

but there is the same behavior. Game is executed but wait parameter does not work.


Report •

#12
August 24, 2010 at 11:28:23
Yeah, that sounds about right; Steam appears to run any program though it's main process. Any time you try to start a Steam application, that application seems to check to see if it was spawned by the "main" Steam program. If not, it tells Steam to start that application, then quits.

Looking for the termination of GameOverlayUi.exe is probably the easiest way to wait for your application to quit (assuming you didn't disable the Steam overlay).

So this VBS will have WMI query the process list every 5 seconds, and it'll return when GameOverlayUi.exe quits.

GetObject("winmgmts:")._
  ExecNotificationQuery("SELECT * " & _
                        "FROM __instancedeletionevent " & _
                        "WITHIN 5 " & _
                        "WHERE TargetInstance ISA 'Win32_Process' " & _
                        "AND TargetInstance.Name = 'gameoverlayui.exe'").NextEvent


Report •

#13
August 24, 2010 at 12:08:42
Thanks a lot for response and constant support! I really appreciate that!

Report •

Ask Question