I have a great batch toggle that will show hidden files when run, then hide hidden files when run again.

I am wondering if I can create a similar file that will kill a series of work applications (ex. cloud services, evernote, etc). when run initially. Then Re-launch those same applications when I'm done doing gaming or whatever it is I'm doing that doesn't need all those programs.

It would be super handy to have. Is this possible to do? Cause most of what I've been seeing has the launch/kill commands in separate bats and I'd just love to hotkey the one.


Here's a one-line batch file you can use:

tasklist /fi "ImageName eq notepad.exe" | find /i "notepad.exe" && taskkill /fi "ImageName eq notepad.exe" || start "" notepad.exe

It will terminate all running instances of Notepad, and if none exist, will launch Notepad. Modify as required. (For example if you want to do more complex stuff, use if-else loops, check for errorlevel etc. See if /? for more.)

| improve this answer | |

You need something telling the .bat file that it had ran before. You could add a registry key, an environment variable, a value to a .txt file... the sky is the limit, you just need to store a value in something that won't be lost when you close the .bat. The simplest solution:

@echo off
if exist ran_once.txt (
start process1.exe
start "path/to/process2.exe"
del /q ran_once.txt
) else (
taskkill /f /im process1.exe
taskkill /f /im process2.exe
echo foo>ran_once.txt

Make sure ran_once.txt is in the same folder as the .bat, or use full/path/to/ran_once.txt

A more elgant solution would be to pause after killing all the processes, opening your game or whatever, and when you return from the game just press any key on the .bat file to continue running and start all the processes again.

| improve this answer | |

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.