Need a Batch toggle that will launch/kill applications when run

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.


Solution 1:

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.)