Reputation: 13
I have already read how to write a .bat file in Windows 7 to open programs but what i want to do now is to have that same .bat to close them if they are already open.
Let's say i run the batch file to open these applications at once to save me some clicks, after i'm done with my work i want to close them without having to go to each one and close them individually. So i want to have the same batch file check if one or all the applications it executed are open to kill their processes like i would do in the Task Manager.
This is the code i'm using in the .bat file:
start "" "C:\Program Files\RocketDock\RocketDock.exe"
start "" "C:\Users\user\Random Folder\Programs\RK_Launcher_04_Beta\RKLauncher.exe"
Upvotes: 1
Views: 4356
Reputation: 1
Taskkill /im RocketDock.exe IF ERRORLEVEL 1 ( Start "" "C:\Program Files\RocketDock\RocketDock.exe" )
Upvotes: 0
Reputation: 20189
You can TASKLIST.EXE
, but I prefer PSLIST.EXE
to check if the process is running. If it's running, use TASKKILL.EXE
to close it.
PSLIST RocketDock.exe
IF ERRORLEVEL 1 (
START "" "C:\Program Files\RocketDock\RocketDock.exe"
) ELSE (
TASKKILL /IM RocketDock.exe
)
I prefer PSLIST.EXE
because it's simpler to check the result.
Upvotes: 1