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
NOTE: Replace 'Zombie1' and 'Zombie2', with your choice from command line TASKLIST

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

Batch: Stop Cortana Memory Hog

Googling for "Microsoft Windows 10 Cortana®" reveals MANY complaints about memory loss - even when Cortana's voice listening and response services are DISABLED / "inactive"! The best advice found on the forums to-date has been "remove" or "rename it"!

Usually a BAD workaround! Especially since it is and error prone IMPOSSIBLE to do it manually.
Therefore this BATCH file is offered with the warning "EXAMPLE only! Do *NOT* attempt this on any computer. This batch file is ONLY OFFERED as an example of the "IF" statement and batch logic flow."

@echo off

rem set statusstring="end of %0"

SET /P ISADMIN=Are you RUNNING THIS AS ADMIN (usually from a shortcut 'RUN AS ADMIN') Y/N: =
if /I NOT "%ISADMIN%"=="Y" goto OOPS
rem KLUDGE to SOLVE MEMORY HOG PROBLEM
rem CORTANA is MICROSOFT's AUDIO LISTENER
rem it can take 20-30% or more of RAM
rem can't MANUALLY RENAME or MOVE it because Task Manager RELOADS it
rem SOLUTION: replace MANUAL steps with BATCH commands

setlocal
rem @echo on

echo step 1 kill SearchUI and rename
IF %ERRORLEVEL% GTR 1 SET ERRSTRING=errlevel%ERRORLEVEL%

for %%x in (ActionUriServer.exe PlacesServer.exe RemindersServer.exe RemindersShareTargetApp.exe SearchUI.exe backgroundTaskHost.exe) do IF EXIST %%x taskkill /T /F /PID %%x

rem taskkill /T /F /PID SearchUI.exe
rem taskkill /T /F /PID backgroundTaskHost.exe

echo step 2 rename folder and/or SearchUI.exe to stop RESTART of Cortana
IF EXIST C:\Windows\SystemApps\Microsoft.Windows.Cortana_cw5n1h2txyewy pushd C:\Windows\SystemApps\Microsoft.Windows.Cortana_cw5n1h2txyewy
IF EXIST SearchUI.exe rename SearchUI.exe zSearchUI.exe
pushd C:\Windows\SystemApps
IF EXIST Microsoft.Windows.Cortana_cw5n1h2txyewy move /Y Microsoft.Windows.Cortana_cw5n1h2txyewy Microsoft.Windows.½Cortana_cw5n1h2txyewy

dir /ad Microsoft.Windows.?C*

GOTO END
:OOPS
set statusstring=RUN AS ADMIN (right click on "%0" and Run As Admin)
echo %statusstring%
:END

echo ....
IF NOT "%ERRSTRING%"=="" echo %ERRSTRING%
ECHO FINISHED BATCH FILE %0
pause
endlocal

 

Batch: Clean Windows Desktop

Runs from any location - moves designated files into a (new) folder on the Windows desktop  named with  today's date.

@echo off
setlocal
rem DESKCLEAN.BAT MAKES DAILY FOLDER FOR WORKING FILES - 
rem UNcomment DEBUGFLAG to troubleshoot / pause
:set debugflag=ANYTHING
:set PAUSEFLAG=ANYTHING
IF NOT "%DEBUGFLAG%"=="" ECHO ON
pushd %userprofile%\Desktop
set filestring = *.pdf;*.txt;*.log;*.xls*;*.sql;*.bak;*.java;*.class;*.jp*;*.gif;*.png;*.bku;*.bkk;*.bmp;*.htm*;*.php;*.css;*.pl;*.py;*.rb;*.doc*;*.ppt*
  rem leave DIRPREFIX blank to create folder with timestamp only 
SET DIRPREFIX=hold
  rem has Day of Week from below "rem set xdate=%xdate:~4%"
  rem makedir with timestamp - the documentation for 
  rem the cryptic string manipulators below is 
  rem cmd's "help for" and "help if"
: below - the SET statements remove from mmm dd, yyyy hh:mm
: in sequence, colon, period, space, slash (replace
: with underscore) 
: then last two remove trailing 1/100ths of second 
: and remove the leading day of week
: xtime is not used unless appended to timestamp
   set xtime=%time::=%
   set xtime=%xtime:.=_%
   set xtime=%xtime: =0%
   set xtime=%xtime:~0,-3%
   set xdate=%date: =_%
   set xdate=%xdate:/=_%rem set xdate=%xdate:~4%
   set timestamp=%xdate%
   set newdir=%DIRPREFIX%_%timestamp%
 rem set newdir=_%timestamp%
 rem remark out above line if you want day of week included at front

rem set timestamp=%xdate%_%xtime% rem this includes timestamp seconds, making unique folder - OMIT to have only one folder per day

for %%x in (%filestring%) do if exist "%%x" if not exist "%newdir%" md "%newdir%"
for %%x in (%filestring%) do if exist "%%x" move "%%x" %newdir%
rem  for %%x in (*.tif;*.jpg;*.jpg;*.gif;*.pdf;*.txt;*.log;*.xls*;*.sql;*.bak;*.bku)
 if exist "%%x" if not exist %newdir% md %newdir%
rem for %%x in (*.tif;*.jpg;*.jpg;*.gif;*.pdf;*.txt;*.log;*.xls*;*.sql;*.bak;*.bku)
if exist "%%x" move "%%x" %newdir%
IF "%DEBUGFLAG%"=="" GOTO END
pause<
:END
popd: UNcomment any below to pause and see variables at work
:set n
:SET D
echo END OF BATCH FILE %0
IF NOT "%PAUSEFLAG%"=="" PAUSE

endlocal

Optionally Uncomment line(s) 5 and/or 6 to watch it work

 
set debugflag=dbf
: (or anything except blank)

set PAUSEFLAG= pflag