Location:
State:
Carrier
Country
Status

Start a program from a batch file


I'm trying to create a batch file that should

- call another batch file
- start a program and then wait for the program to close
- call another batch file

My goal with this is to work around an issue in Windows 10 where the screensaver won't work when I have my game controllers connected. I already created two batch files where one of them enables my game controllers and the other one disables them. Both these batch files work just fine.

However I now want to create a third batch file that will do what listed above - first call the batch file that will enable my game controllers, then start my program which is an executable and then after I exited out of the program the batch file that will disable my game controllers should be called.

Here's what I've tried but this doesn't work, it will only run the first batch file enabling my game controllers.

Code:
"c:utilGame controllers - Enable.cmd" start "P:Program Files (x86)Lockheed MartinPrepar3D v2Prepar3D.exe" "c:utilGame controllers - Disable.cmd"
Thanks in advance for any help.

The start command on line 2 treats your path in quotes as a window title only.
Add the /d switch to declare the path first then call the executable.

Code:
start /d "P:Program Files (x86)Lockheed MartinPrepar3d v2" Prepar3D.exe
reference:

Many thanks!

However your suggested command only works when I run it manually from the command line. Having it in a .cmd file double-clicking the .cmd file only executes the first line enabling the game controllers. I also tried creating a shortcut to the .cmd file and tick the 'Run as Administrator' option but still no go and same thing when right-clicking the .cmd file choosing 'Run as Administrator'.

So...for whatever reason the command you suggested works perfectly fine when you run it manually from the command line but not when it's included in a .cmd file.

Then there's the other question/problem how to make the .cmd file wait to execute the third line (disabling my game controllers) until Prepar3D.exe has quit.

However your suggested command only works when I run it manually from the command line.
Try the following as your batch file:

Code:
start /b "" "c:utilGame controllers - Enable.cmd" start /wait "" "P:Program Files (x86)Lockheed MartinPrepar3D v2Prepar3D.exe" start /b "" "c:utilGame controllers - Disable.cmd"
Make sure the last line in your .cmd files is EXIT

Prefaced 1st & 3rd line with start /b so that all 3 commands are called from the same parent and you can see them launch to confirm. The double quotes on each line are a kludge of sorts to get around the window title parameter and be able to use long filenames/paths.

Try the following as your batch file:

Code:
start /b "" "c:utilGame controllers - Enable.cmd" start /wait "" "P:Program Files (x86)Lockheed MartinPrepar3D v2Prepar3D.exe" start /b "" "c:utilGame controllers - Disable.cmd"
Make sure the last line in your .cmd files is EXIT

Prefaced 1st & 3rd line with start /b so that all 3 commands are called from the same parent and you can see them launch to confirm. The double quotes on each line are a kludge of sorts to get around the window title parameter and be able to use long filenames/paths.
Sorry for the late reply, have been building a new computer but now I'm finished and just tried what you suggest above and it works like a charm so many thanks !!

This will be perfect until Microsoft hopefully addresses the issue where the screensaver in Win10 won't work with your game controllers connected and enabled.

Start a program from a batch file