Windows 10: VBS to start a EXE. Then stop a service. Once closed start service back up and exit script.

Tristan George
Tristan George used Ask the Experts™
on
Need a script that will:

1. start a program in:  D:\Program Files (x86)\Steam\steamapps\common\DARK SOULS III\Game\DarkSoulsIII.exe
2. wait 5 Seconds, then STOP the Service: "windows management instrumentation"
3. Every 60 seconds check if DarkSoulsIII.exe is running. If it is do NOTHING, but loop back to the 60 second check.
4. If it is NOT, then START the service "windows management instrumentation"
5. Kill script. Done.

Thanks for everyones help. I am thinking this is pretty simple, but examples I find similar are for more complex scripts which is actually making doing the above hard to know how.

Thanks again.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Test your restores, not your backups...
Top Expert 2016
Commented:
I would do this using a small BAT script, much easier.  The below should be a good starting point for you.

Be aware that you will need to run this in Administrative mode I believe to stop WMI.

Also be aware that while stopping WMI will stop all dependent services, the opposite is not true, when you restart WMI any services that were stopped because they depended on it will not be restarted, you would have to start each of those manually.  You can see what services depend on WMI by doing the following command:

sc enumdepend winmgmt

@echo off
setlocal

rem 1. start a program in:  D:\Program Files (x86)\Steam\steamapps\common\DARK SOULS III\Game\DarkSoulsIII.exe
start "" "D:\Program Files (x86)\Steam\steamapps\common\DARK SOULS III\Game\DarkSoulsIII.exe"

rem 2. wait 5 Seconds, then STOP the Service: "windows management instrumentation"
timeout /t 5 /nobreak
net stop winmgmt

rem 3. Every 60 seconds check if DarkSoulsIII.exe is running. If it is do NOTHING, but loop back to the 60 second check.
:Loop
timeout /t 60 /nobreak
tasklist /FI "imagename eq DarkSoulsIII.exe" | find /I "DarkSoulsIII.exe" >NUL 2>&1 && goto :Loop

rem 4. If it is NOT, then START the service "windows management instrumentation"
net start winmgmt

rem 5. Kill script. Done.
exit /b

Open in new window

~bp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial