Batch script to kill a process if not responding in a for loop

1.7k views Asked by At

I am trying to install some windows standalone update files and to do this I need to use wusu.exe. Every now and again wusu.exe will hang. I have created a batch file called prereqs.bat and in this file I have calls to the wusu.exe. I need the code to kill wusu.exe if it hangs, and retry it again.

This is my code as it stands now:

:PreReqs32
taskkill /im prereqs32.bat /f
taskkill /im wusa.exe /f

when it loops back, it kills both the batch file and wusa.exe

start cmd /k c:\windows\temp\prereqs.bat

An outside process so that I can kill wusu.exe if things go awry.

timeout /t 240 /NOBREAK

this timeout is to wait until the install is complete which is sometimes not enough.

taskkill /im "[wusa.exe]" /fi "STATUS eq NOT RESPONDING"
if "%ERRORLEVEL%"=="1" goto PreReqs32

Is there a way for some sort of FOR loop, with logic to exit if the status is not "not responding"?

Also, as a bonus, is there a way to forgo the timeout and just "wait" for prereqs.bat to be complete before moving on, assuming that wusu.exe has not hung?

0

There are 0 answers