@echo off
rem :: code until
rem :: to kill any process
set "_kill=cmd.exe timeout.exe"
set "_title=Keep_Yourself_Alive"
<con: title <nul & title %_title%
pushd %__AppDir__% && for /f tokens^=1^,3delims^=^" %%i in ('
tasklist /v /fo csv ^|findstr /i "%_kill%"^|findstr /vi "%_title%"
')do 2>nul <con: taskkill.exe /f /pid %%j >nul | echo\Bye Bye %%j:%%i
<con: rem./ & shutdown /and /your /flags /here & popd
rem :: more code came here, after to kill process ...
- I never realized that
Shutdown
were attentive to waiting for theTimeout
good to know...
1. Assign a unique Title
to your bat:
@echo off
Title Keep_Yourself_Alive
2. List with For /F
the process PID
of each CMD
and Timeout
with Tasklist
and Finsdtr
:
for /f tokens^=3delims^=^" %%i in ('tasklist /v /fo csv|findstr "cmd.exe timeout.exe"...
3. One additional Findstr
can be used to list only PIDs
that does not match your unique bat TaskkillTitle
... ^|findstr /vi "Keep_Yourself_Alive" ...
4. Use Taskkill
with PID
to kill the entire CMD.exe
+ Timeout
process (if running*)
... ')do taskkill /F /PID %%i
Additional resources: