Start a program from a batch file


  1. Posts : 107
    Windows 10 Pro
       #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 Computer


  2. Posts : 5
    Windows 10
       #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 Computer


  3. Posts : 107
    Windows 10 Pro
    Thread Starter
       #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 Computer


  4. Posts : 5
    Windows 10
       #4

    WebMaximus said:
    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 Computer


  5. Posts : 107
    Windows 10 Pro
    Thread Starter
       #5

    LetsWindows10 said:
    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 Computer


 

  Related Discussions
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 22:57.
Find Us




Windows 10 Forums