1. Joined : Aug 2015
    Posts : 28
    Windows 10 Pro
       19 Aug 2015 #1

    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:\util\Game controllers - Enable.cmd"
    start "P:\Program Files (x86)\Lockheed Martin\Prepar3D v2\Prepar3D.exe"
    "c:\util\Game controllers - Disable.cmd"
    Thanks in advance for any help.
      My System SpecsSystem Spec


  2. Joined : Jul 2015
    Posts : 5
    Windows 10
       20 Aug 2015 #2

    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 Martin\Prepar3d v2" Prepar3D.exe
    reference: https://technet.microsoft.com/en-us/.../Cc770297.aspx
      My System SpecsSystem Spec


  3. Joined : Aug 2015
    Posts : 28
    Windows 10 Pro
       20 Aug 2015 #3

    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.
      My System SpecsSystem Spec


  4. Joined : Jul 2015
    Posts : 5
    Windows 10
       26 Aug 2015 #4

    WebMaximus said: View Post
    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:\util\Game controllers - Enable.cmd"
    start /wait "" "P:\Program Files (x86)\Lockheed Martin\Prepar3D v2\Prepar3D.exe"
    start /b "" "c:\util\Game 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.
      My System SpecsSystem Spec


  5. Joined : Aug 2015
    Posts : 28
    Windows 10 Pro
       05 Sep 2015 #5

    LetsWindows10 said: View Post
    Try the following as your batch file:

    Code:
    start /b "" "c:\util\Game controllers - Enable.cmd"
    start /wait "" "P:\Program Files (x86)\Lockheed Martin\Prepar3D v2\Prepar3D.exe"
    start /b "" "c:\util\Game 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.
      My System SpecsSystem Spec


 


Similar Threads
Thread Forum
Batch File - Add to New Context Menu in Windows 10
How to Add Windows Batch File to New Context Menu in Windows 10 A .bat file is a batch file that consists of a series of commands to be executed by the command line interpreter, stored in a plain text file. The New context menu allows users...
Tutorials
Batch file - Unable to start a program minimized
I've been trying to figure this out for a while now and I can't. I've looked at tons of small tips online to get this working but it doesn't work at all. I have a batch file which causes various programs to start when opened. However, one of them...
General Support
How I add a shortcut for a DOS program to the Start Menu?
On the 32 bit version of W10, how do I add a shortcut for a DOS program to the Start Menu?
Software and Apps
System Info Batch File
Hi Everyone, I thought it may be interesting to get input from others regarding this batch file. I was hoping for suggestions about: Information to add to the report. Ways of making the current code more efficient. Etc... A while back i...
Chillout Room
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 17:19.
Find Us
Twitter Facebook Google+



Windows 10 Forums