Script for Running Program

Discussion in 'Scripting' started by BrokenDaily, Sep 8, 2017.

  1. BrokenDaily

    BrokenDaily MDL Junior Member

    Jun 14, 2017
    87
    1
    0
    new at this, so what im looking for is to make either a .bat script, or a powershell script that does the following

    script runs program A, then program B;, but if running this script and program A is already running, then ignore the "Start Program A" command and run program B

    what would I need to type/copy in this case?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. tonto11

    tonto11 MDL Addicted

    Jun 18, 2012
    605
    272
    30
    I'm no programmer, but the script should look something like

    test is program A running
    if A is not running then run program A
    if A is running
    run program B

    now all we've got to do is turn this pseudocode into a script
    and test it

    ...T
     
  3. dhjohns

    dhjohns MDL Guru

    Sep 5, 2013
    3,276
    1,731
    120
    #3 dhjohns, Sep 9, 2017
    Last edited: Sep 9, 2017
    Adjust for your paths
    Code:
    tasklist /FI "IMAGENAME eq notepad.exe" 2>NUL | find /I /N "notepad.exe">NUL
    if "%ERRORLEVEL%"=="0" E:\Portable_Files\Notepad++\Files\notepad++.exe
    
    if "%ERRORLEVEL%"=="1"  E:\Portable_Files\Notepad++\Files\notepad++.exe | notepad.exe
    There is a command window which stays open with this. You can either close this manually, or as I prefer, make it invisible with a vbs script. I tested these file out on my desktop, so you will need to plug the correct path for your main command file into the vbs file. You would run the vbs file instead of the command script. The vbs file will run the command script invisibly.
    Code:
    Dim WinScriptHost
    Set WinScriptHost = CreateObject("WScript.Shell")
    WinScriptHost.Run Chr(34) & "%USERPROFILE%\Desktop\test.cmd" & Chr(34), 0
    Set WinScriptHost = Nothing
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. BrokenDaily

    BrokenDaily MDL Junior Member

    Jun 14, 2017
    87
    1
    0
    the programs I got are one called VDX_x64.exe, and the other 2 are console emulators (dolphin and pcsx2); this vdx program is needed for me to use a ds4 controller correctly (minus rumble support)

    as for dhjohns reply, do I take the 1st code, and after saving it as a .bat file, save the 2nd code as a .vbs script, or put both in one .vbs script?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. dhjohns

    dhjohns MDL Guru

    Sep 5, 2013
    3,276
    1,731
    120
    Save the second code as vbs with path to your bat file in line three. Then you just run the vbs script. It will call the bat file.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. BrokenDaily

    BrokenDaily MDL Junior Member

    Jun 14, 2017
    87
    1
    0
    #6 BrokenDaily, Sep 9, 2017
    Last edited: Sep 12, 2017
    (OP)
    I tried the code I got, and for the bat/cmd file, I put the vdx in the 1st line and dolphin in the 2nd, no go, so I switched it, again, no go

    am I doing something wrong, putting one line in the wrong spot or something else
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...