Make BAT file do double check before taskkill?

Scorpion Ghost

Elite Member
Executive VIP
Jr. VIP
Joined
Mar 22, 2013
Messages
9,143
Reaction score
10,489
I use a BAT file to kill Firefox browsers that are stuck on "Not Responding".

I have this very simple BAT file:

Code:
@echo off
taskkill /im "firefox.exe" /fi "STATUS eq NOT RESPONDING" /f >nul

When I run it, it checks all the "firefox.exe" running on the computer, and it Kills the ones that are showing "Not Responding" in task manager.

It works well.

---

The problem is that sometimes a browser could go "Not Responding" for a couple of seconds, and then return to normal function. And if the BAT file runs during those couple of seconds, it will kill that browser. I don't want that.

Is there a way for the BAT code to do like a double check on all the browsers, like 10 seconds apart between checks, and only close the browsers that are stuck on "Not Responding" during both checks?
 
BAT file has no clue as to what's going on, and it's rather impossible to make it so.

You can add a sleep delay between kills, but it won't answer your issue either.
 
place a sleep may be? So, the logic becomes..

if status eq not responding, sleep 2 seconds and check status again. if still not responding, kill the pid
 
BAT file has no clue as to what's going on, and it's rather impossible to make it so.

You can add a sleep delay between kills, but it won't answer your issue either.

Impossible? That's not a nice word :D

There's gotta be a way.

place a sleep may be? So, the logic becomes..

if status eq not responding, sleep 2 seconds and check status again. if still not responding, kill the pid

Okay, a simple sleep won't work because then the logic would become:

run BAT file code, it kills programs
sleep delay
run BAT file code, it kills programs

---

If we put some sort of intelligent code to do this:

run bat file code, if it finds "Not Responding"...
sleep 10 sec...
run bat file code, if it finds "Not Responding", kill it

Then the first run is kinda redundant, because a mistake could happen on the second run anyway.

The only difference would be if the BAT file somehow knew that the program that was "Not Responding" on the first run before the sleep, is the same program that is "Not Responding" on the second run, at which point it kills it.

But can a BAT file display such intelligence?
 
Impossible? That's not a nice word :D

There's gotta be a way.



Okay, a simple sleep won't work because then the logic would become:

run BAT file code, it kills programs
sleep delay
run BAT file code, it kills programs

---

If we put some sort of intelligent code to do this:

run bat file code, if it finds "Not Responding"...
sleep 10 sec...
run bat file code, if it finds "Not Responding", kill it

Then the first run is kinda redundant, because a mistake could happen on the second run anyway.

The only difference would be if the BAT file somehow knew that the program that was "Not Responding" on the first run before the sleep, is the same program that is "Not Responding" on the second run, at which point it kills it.

But can a BAT file display such intelligence?
No, it won't know what to do.

If you really want to go down that route, use python or autoit, where you have more control.

CMD/bat was never designed to offer that level of control over things.

There are some ways you can make it work with if/else clauses, but I assure you not worth the time invested by you or a coder to make it worth the money.
 
get the pid of the process? then for killing you could probably do (not sure about windows, i am a mac/linux guy).

kill -9 pid

Other than that, I dunno if it can be done with batch script to be honest.
 
You have to make two or three steps to check if it is not responding with some delay.
If it reaches to step 3rd with all the steps seeing not responsing then do kill firefox
Else start again from step 1
 
You could have an array in that batch file, with the number of not responding attempts for a specific process, and after x times should kill it.
 
Back
Top