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

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.
Tristan GeorgeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.