Batch: Kill Zombie Tasks

@echo off

rem TMstatus.bat set zombie vars to full or partial task name to test remove from Task Manager
Demonstrates (a) Timestamps (b) FOR parsing of delimited fields and (c) IF logical comparisons
Warning: Replace 'Zombie1' and 'Zombie2', currently set to kill CHROME and APPLEUPDATE


setlocal
set zombie1=firef
set zombie2=SoftwareUpdate
set hasargument=no_argument
if not "%1"=="" set hasargument=%1
:maketimestamp
 

set xtime=%time::=%
set xtime=%xtime:.=_%
set xdate=%date: =_%
set xdate=%xdate:/=_%
rem set xdate=%xdate:~4%
set xtime=%xtime:~0,-3%
rem set timestamp=%xdate%_%xtime%
set timestamp=%xdate%
rem set newdir=_hold_%timestamp%
set outputfile=taskman%xdate%.log 

:randomfile
set randfile=delete%random%.txt
TASKLIST /NH /FI "IMAGENAME eq %zombie1%*"
TASKLIST /NH /FI "IMAGENAME eq %zombie2%*" 

TASKLIST /NH /FI "IMAGENAME eq %zombie1%*" >> %randfile%
TASKLIST /NH /FI "IMAGENAME eq %zombie2%*" >> %randfile% 

for /f "tokens=3" %%f in ('find /i /c "%zombie1%" %randfile%') do set whatcount1=%%f
for /f "tokens=3" %%g in ('find /i /c "%zombie2%" %randfile%') do set whatcount2=%%g
echo %timestamp% %0 count of %zombie1% is: %whatcount1%
echo %timestamp% %0 count of %zombie1% is: %whatcount2% 

echo %timestamp% %0 %hasargument% count of %zombie1% is: %whatcount1% >> %outputfile%
echo - %timestamp% %0 %hasargument% count of %zombie2% is: %whatcount2% >> %outputfile%
rem if %whatcount% GTE 2 TASKKILL /S system /U username /P password /FI "IMAGENAME eq note*"
if %whatcount1% GEQ 1 TASKKILL /FI "IMAGENAME eq %zombie1%*" >> %outputfile%
if %whatcount2% GEQ 1 TASKKILL /FI "IMAGENAME eq %zombie2%*" >> %outputfile% 

DEL %randfile%
:skip
 

ECHO FOR MORE DETAILS try command line: TASKLIST /M /FI "IMAGENAME eq SubSys*" 

if "%1"=="" echo end of %0
if "%1"=="" pause 

endlocal

Batch: Clean Desktop

@echo off

REM moves graphic files to "Screenshots", other files to folder "_Desktop<timestamp>
REM demonstrates current date/time stamps AND "for (each) loops

setlocal
rem set debug=anythingbutblank
pushd %userprofile%\Desktop
if not exist Screenshots md Screenshots
:makedir with timestamp
set xtime=%time::=%
set xtime=%xtime:.=_%
set xdate=%date: =_%
set xdate=%xdate:/=_%
rem set xdate=%xdate:~4%
set xtime=%xtime:~0,-3%
rem set timestamp=%xdate%_%xtime%
set timestamp=%xdate%
set newdir=_Desktop_%timestamp%
if not "%debug%"=="" @echo on
if not exist %newdir% md %newdir%
rem excluded LNK URL
if not "%debug%"=="" echo newdir is: %newdir%
rem for %%x in (*.url *.lnk *.jpg *.pdf *.txt *.bak *.ahk *.doc* *.sql *.xls* *.png *.xml *.bmp *.gif *.log *.rtf *.htm? *.msg *.zip) do if exist "%%x" move "%%x" %newdir%
for %%x in ( *.csv *.txt *.vsd *.css *.cs *.cpp *.bak *.php *.js *.json *.doc* *.sql *.xls* *.xml *.java *.py *.log *.rtf *.htm? *.msg *.eml *.gz *.zip) do if exist "%%x" move /-Y "%%x" %newdir%
for %%x in ( *.jpg *.pdf *.png *.bmp *.gif ) do if exist "%%x" move /-Y "%%x" Screenshotsif not exist Shortcuts md Shortcutsfor %%x in ( *.lnk *.URL ) do if exist "%%x" move /-Y "%%x" Shortcuts

:set n
:set x
echo end batch file %0
pause

endlocal