Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

Thanks for any help in advance!

share|improve this question

2 Answers 2

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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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