1

I want to start Spotify, Toastify and EZblocker at once, and exit them, if they are running at once.

Starting them is easy, just the start command, stopping isn't, I saw many answers on SO, but I don't know batch and I don't know how to do if else, it should be simple but I have never learnt batch. Plus I was wondering if autohotkey would be a better solution. I'm on windows 10.

Note that Toastify is able to start and stop Spotify, therefore I just need to start and stop EZblocker and Toastify.

1 Answer 1

2

How about a .bat file that closes the apps on click?

Paste the following into notepad and save as a .bat file

set EXE=spotify.exe

FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto FOUND

start "" "PATH TO SPOTIFY.EXE"
start "" "PATH TO TOASTIFY.EXE"
start "" "PATH TO EZBLOCKER.EXE"
goto FIN
:FOUND

taskkill /IM spotify.exe
taskkill /IM toastify.exe
taskkill /IM ezblocker.exe

:FIN
  • set EXE - Your executable file (spotify.exe etc.)
  • FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto FOUND - check if EXE alias, spotify.exe, is running.
  • start "" "PATH TO SPOTIFY.EXE" - Launch spotify and other apps if not running.
  • taskkill /IM spotify.exe- Kill spotify and other apps if running.

Get the process name from the task manager and change the running .exe as applicable.

Where /IM will send the terminate signal to the application. However, for certain application such as Spotify, the application might simply minimize to the taskbar. Use /F to force close them in that case.

3
  • Could you add if else to your script to make it work like this: if no process (checking one of the 3 is enough) is running then start, else close which is what you did
    – Lynob
    Oct 4, 2016 at 16:12
  • Done. I tested with a single program only - but it should work if you tinker about it with, cheers.
    – Carrein
    Oct 4, 2016 at 17:04
  • Doesn't exit though, but works well,thanks so much
    – Lynob
    Oct 5, 2016 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.