process kill plus(top mem usage)
Posted by: disrupted
Date: March 03, 2010 07:32AM

kills the top process by memory usage. this can be useful when a program freezes ,consuming above normal memory and doesn't close normally, instead of opening the taskmanager and looking for the program, kill it with one click also when testing programs and a program gets in a loop due to bad coding you can kill it instantly.

the program uses tasklist to write a log file which it then parses, the command is executed through a bat file (testshit.bat) which the user can edit to assign filters to top memory or filter out certain programs or windows services which must not be included since killing them might cause system restarts or you can filter out your regular background programs which should be excluded. only the top memory using program will be killed.

for 2k and above only:


; AutoIt Version: 3.3.0
; Language: mary poppins
; Platform: Win9x/NT
; Author: yannis
#include <string.au3>
#include <file.au3>
#include <Misc.au3>
#include <Math.au3>
#Include <Array.au3>
if _Singleton("processkill",0) = 0 Then

if WinExists("Synchronization Error...") Then
; this command is ffor nad player that can get stuck when playing some vbr(you probably won't encounter that problem)
elseif processe-xists("autoit3.exe") then
;kills instances of autoit3, useful when running badly coded scripts(loop errors)

;detects of cmdline/dos/batch files are disabled globally and enables them temporarily when the cript executes the bat
$cmdstats=RegRead( "HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System", "DisableCMD")
RegWrite("HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System" ,"DisableCMD", "REG_DWORD", 0)

$proclogbat=(@scriptdir & "\testshit.bat")
ShellExecute ($proclogbat , "" , "", "Open", @SW_HIDE)
$processstr1=filereadline($proclist, 3)
$getprocnam1=StringInStr ($processstr1, """" , 0, 2 )
$getprocnam2=StringMid($processstr1, 1, $getprocnam1)
$getprocnam3=StringReplace($getprocnam2, """", "")
$processstr2=filereadline($proclist, 4)
;msgbox(48, $getprocnam3, $getprocnam3)

if $processstr2=("") then
$getprocnam12=StringInStr ($processstr2, """" , 0, 2 )
$getprocnam22=StringMid($processstr2, 1, $getprocnam12)
$getprocnam32=StringReplace($getprocnam22, """", "")
;msgbox(48, $getprocnam32, $getprocnam32)

$processstr3=filereadline($proclist, 5)
$getprocnam13=StringInStr ($processstr3, """" , 0, 2 )
$getprocnam23=StringMid($processstr3, 1, $getprocnam13)
$getprocnam33=StringReplace($getprocnam23, """", "")
;msgbox(48, $getprocnam33, $getprocnam33)

$processstr4=filereadline($proclist, 6)
$getprocnam14=StringInStr ($processstr4, """" , 0, 2 )
$getprocnam24=StringMid($processstr4, 1, $getprocnam14)
$getprocnam34=StringReplace($getprocnam24, """", "")
;msgbox(48, $getprocnam34, $getprocnam34)

;get memory
$getmem1=StringInStr ($processstr1, """" , 0, 9 )
$getmem2=Stringtrimleft($processstr1, $getmem1)
$getmem3=StringReplace($getmem2, """", "")
$getmem4=StringReplace($getmem3, " k", "")
$getmem5=StringReplace($getmem4, ",", "")
;msgbox(48, $getmem5, $getmem5)

$getmem12=StringInStr ($processstr2, """" , 0, 9 )
$getmem22=Stringtrimleft($processstr2, $getmem12)
$getmem32=StringReplace($getmem22, """", "")
$getmem42=StringReplace($getmem32, " k", "")
$getmem52=StringReplace($getmem42, ",", "")
;msgbox(48, $getmem52, $getmem52)

$getmem13=StringInStr ($processstr3, """" , 0, 9 )
$getmem23=Stringtrimleft($processstr3, $getmem13)
$getmem33=StringReplace($getmem23, """", "")
$getmem43=StringReplace($getmem33, " k", "")
$getmem53=StringReplace($getmem43, ",", "")
;msgbox(48, $getmem53, $getmem53)

$getmem14=StringInStr ($processstr4, """" , 0, 9 )
$getmem24=Stringtrimleft($processstr4, $getmem14)
$getmem34=StringReplace($getmem24, """", "")
$getmem44=StringReplace($getmem34, " k", "")
$getmem54=StringReplace($getmem44, ",", "")
;msgbox(48, $getmem54, $getmem54)

; restores original setting for batch dos commands(case disabled)
RegWrite("HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System" ,"DisableCMD", "REG_DWORD", $cmdstats)
$gethimem=($getmem5 & "," & $getmem52 & "," & $getmem53 & "," & $getmem54)
$avArray = StringSplit($gethimem, ",")
$maxprocess= _ArrayMax($avArray, 1, 1)
;msgbox(0,'Max Numeric value', _ArrayMax($avArray, 1, 1))

;find program by top memory usage by placing memory usage values in an array
if $maxprocess=$getmem5 then
;msgbox(48, "highest memory is", "process one")
if $maxprocess=$getmem52 then
;msgbox(48, "highest memory is", "process two")
elseif $maxprocess=$getmem53 then
;msgbox(48, "highest memory is", "process three")
;msgbox(48, "highest memory is", "process four")


while processe-xists($processtokill)


Func killnad()

Func killautoit()
while processe-xists("autoit3.exe")

;$makeprlog=("c:\windows\system32\tasklist.exe /fi " & """" & "imagename ne explorer.exe" & """" &" /fi " & """" &" /fi " & """" & "imagename ne liveipplus.exe" & """" &" /fi " & """" & "imagename ne freevoice.exe" & """" &" /fi " & """" & "imagename ne csrss.exe" & """" &" /fi " & """" & "imagename ne svchost.exe" & """" &" /fi " & """" & "imagename ne wmiprvse.exe" & """" &" /fi " & """" & "imagename ne OBJECT~1.EXE" & """" &" /fi " & """" &" /fi " & """" & "imagename ne ctfmon.exe" & """" &" /fi " & """" &" /fi " & """" &" /fi " & """" &" /fi " & """" & "imagename ne HydraDM.exe" & """" &" /fi " & """" & "imagename ne autoit3.exe" & """" &" /fi " & """" &" /fi " & """" &" /fi " & """" & "memusage gt 5000" & """" & " /fo csv >c:\list.txt")

!IMPORTANT ediing the batch file(testshit.bat)

the bat default looks like this:

tasklist /fi "imagename ne explorer.exe" /fi "imagename ne lsass.exe" /fi "imagename ne liveipplus.exe" /fi "imagename ne freevoice.exe" /fi "imagename ne csrss.exe" /fi "imagename ne svchost.exe" /fi "imagename ne wmiprvse.exe" /fi "imagename ne OBJECT~1.EXE" /fi "imagename ne ctfmon.exe" /fi "imagename ne Console.exe" /fi "imagename ne autoit3.exe" /fi "imagename ne tasklist.exe" /fi "imagename ne Ati2evxx.exe" /fi "imagename ne processkillplus.exe" /fi "imagename ne client.exe" /fi "imagename ne winlogon.exe" /fi "imagename ne spoolsv.exe" /fi "imagename ne mbprobe.exe" /fi "imagename ne ctfmon.exe" /fi "imagename ne spoolsv.exe" /fi "memusage gt 4600" /fo csv >c:\list.txt

some of the entries are system services and should not be removed but you ca always add more programs to be filtered out i.e. those programs will never be included regardless of their memory usage(protected), client lsass winlogon explorer ctfmon csrss are examples f services and programs that must not be removed(always excluded)

for example if you want to exclude a program like k-meleon, then add this string within the bat command
/fi "imagename ne k-meleon.exe"

you can also specify the memory usage to return programs, the default is 4600, meaning programs using memory exceeding 4600 kb will be returned(except those excluded by fi/ ne
4600 is a bit low but is a personal preference due to autoit scripts that can get stuck even with low memory usage.. you can increase that value.. i think the norm to start checking for programs with hi mem usage is around 20000kb but that may vary from system to system..virtual memory/page file etc so edit this value to what's best for your system or normal idle usage

use notepad or any text editor to edit testshit.bat

extract anywhere you like, create a shortcut to processkillplus on your desktop or launcher

Re: process kill plus(top mem usage)
Posted by: panzer
Date: March 10, 2010 04:30PM
Re: process kill plus(top mem usage)
Posted by: disrupted
Date: March 11, 2010 03:01AM

i don't like those programs for few reasons.. i don't like things running in the background all the time, antifreeze thingies and another reason is that all those programs detect a program about to hang by cpu usage, this is not always the case..many will freeze or hang without much cpu usage but you can easily detect them by memory very badly coded autit scripts that get caught in a loop(my case grinning smiley) and for certain tasks, i don't like a gui..simple cmdline will do to execute with one click... unfortunately cmdline tools are becoming less on offer sad smiley

Re: process kill plus(top mem usage)
Posted by: panzer
Date: March 16, 2010 01:30AM

Yeah, but they came handy if you did not backed-up your work on comp. In that case, you should try with Antifreeze instead of reboot and loose all your work.

Otherwise, just reboot.

K-Meleon forum is powered by Phorum.