jerome Posted December 8, 2006 Posted December 8, 2006 (edited) Hello, A Ram monitorwith an optimization option in system tray! JD expandcollapse popup#include <GuiConstants.au3> RAMRun() Func RAMRun() RAMInit() TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "RAMExit") TraySetState() While 1 Sleep(50) WEnd EndFunc Func RAMInit() Opt("RunErrorsFatal", 0) Opt("GUIOnEventMode", 1) Opt("TrayOnEventMode",1) Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. Opt("GUIResizeMode", $GUI_DOCKSIZE+$GUI_DOCKLEFT) TrayCreateItem("Memory audit") TrayItemSetOnEvent(-1, "RAMmonitor") EndFunc Func RAMmonitor() Opt("GUIOnEventMode", 0) $gui = GuiCreate("Memory monitor", 544, 190,-1, -1 , $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS) $Label_1 = GuiCtrlCreateLabel("Physical RAM:", 10, 10, 130, 20, ) GUICtrlSetBkColor($Label_1, $GUI_BKCOLOR_TRANSPARENT) $Progress_1 = GuiCtrlCreateProgress(10, 30, 520, 20) $Label_2 = GuiCtrlCreateLabel("Pagefile size:", 10, 60, 130, 20) GUICtrlSetBkColor($Label_2, $GUI_BKCOLOR_TRANSPARENT) $Progress_2 = GuiCtrlCreateProgress(10, 80, 520, 20) $Label_3 = GuiCtrlCreateLabel("Virtual RAM size:", 10, 110, 130, 20) GUICtrlSetBkColor($Label_3, $GUI_BKCOLOR_TRANSPARENT) $Progress_3 = GuiCtrlCreateProgress(10, 130, 520, 20) $Button = GUICtrlCreateButton("Optimize", 480, 160, 60, 25) GuiSetState() $nb=500 While 1 $nb=$nb+10 If $nb > 500 Then $memory = MemGetStats ( ) $RamFree = Round(100*($memory[1]-$memory[2])/$memory[1], 1) GUICtrlSetData ($Progress_1, $RamFree) GUICtrlSetData ($Label_1, "Physical RAM: " & $RamFree & "%") $RamFree = Round(100*($memory[3]-$memory[4])/$memory[3], 1) GUICtrlSetData ($Progress_2, $RamFree) GUICtrlSetData ($Label_2, "Pagefile size: " & $RamFree & "%") $RamFree = Round(100*($memory[5]-$memory[6])/$memory[5], 1) GUICtrlSetData ($Progress_3, $RamFree) GUICtrlSetData ($Label_3, "Virtual RAM size: " & $RamFree & "%") $nb=0 EndIf Sleep(10) $msg = GuiGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $Button Then MemoryOptimize() WEnd GUIDelete($gui) Opt("GUIOnEventMode", 1) EndFunc Func RAMExit() Exit EndFunc ;--------------------------------------------------------------- ;- Reduce memory ;--------------------------------------------------------------- Func MemoryOptimize() $memory1 = MemGetStats ( ) Do ReduceMemory() $list = ProcessList() For $i=1 To $list[0][0] ReduceMemory($list[$i][1]) Next $memory2 = $memory1 $memory1 = MemGetStats ( ) Until $memory1[2] >= $memory2[2] EndFunc Func ReduceMemory($i_PID = -1) If $i_PID <> -1 Then Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID) Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0]) Else Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1) EndIf Return $ai_Return[0] EndFunc;==> ReduceMemory() Edited December 8, 2006 by jerome
HackerZer0 Posted December 8, 2006 Posted December 8, 2006 hey sort of a problem with your script... you seem to have left out a key function... MemoryOptimize() ... i got an error when clicking the button... Earn money on CASHCRATE by sitting around doing nothing..
jerome Posted December 8, 2006 Author Posted December 8, 2006 hey sort of a problem with your script... you seem to have left out a key function...MemoryOptimize() ...i got an error when clicking the button...You're right, I'll correct! Sorry
HackerZer0 Posted December 8, 2006 Posted December 8, 2006 wow nice job, my physical ram usage dropped about 15% nice work : ) Earn money on CASHCRATE by sitting around doing nothing..
jftuga Posted December 8, 2006 Posted December 8, 2006 May I suggest that your script exclude these 4 critical system processes: csrss, smss, winlogon, and lsass? Running ReduceMemory() on them can lead to system instability (at least on XP). -John Admin_Popup, show computer info or launch shellRemote Manager, facilitates connecting to RDP / VNCProc_Watch, reprioritize cpu intensive processesUDF: _ini_to_dict, transforms ini file entries into variablesUDF: monitor_resolutions, returns resolutions of multiple monitorsReport Computer Problem, for your IT help deskProfile Fixer, fixes a 'missing' AD user profile
jerome Posted December 8, 2006 Author Posted December 8, 2006 Yes, you are right, it's better. I Correct it: expandcollapse popup#include <GuiConstants.au3> RAMRun() Func RAMRun() RAMInit() TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "RAMExit") TraySetState() While 1 Sleep(50) WEnd EndFunc Func RAMInit() Opt("RunErrorsFatal", 0) Opt("GUIOnEventMode", 1) Opt("TrayOnEventMode",1) Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. Opt("GUIResizeMode", $GUI_DOCKSIZE+$GUI_DOCKLEFT) TrayCreateItem("Memory audit") TrayItemSetOnEvent(-1, "RAMmonitor") EndFunc Func RAMmonitor() Opt("GUIOnEventMode", 0) $gui = GuiCreate("Memory monitor", 544, 130,-1, -1 , $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS) $Progress_1 = CreateProgress(10, 10, 520, 20) $Progress_2 = CreateProgress(10, 40, 520, 20) $Progress_3 = CreateProgress(10, 70, 520, 20) $Button = GUICtrlCreateButton("Optimize", 470, 100, 60, 25) GuiSetState() $nb=500 While 1 $nb=$nb+10 If $nb > 500 Then $memory = MemGetStats ( ) UpdateProgress($Progress_1, Round(100*($memory[1]-$memory[2])/$memory[1], 1), "Physical RAM: ") UpdateProgress($Progress_2, Round(100*($memory[3]-$memory[4])/$memory[3], 1), "Pagefile size: ") UpdateProgress($Progress_3, Round(100*($memory[5]-$memory[6])/$memory[5], 1), "Virtual RAM size: ") $nb=0 EndIf Sleep(10) $msg = GuiGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $msg = $Button Then MemoryOptimize() WEnd GUIDelete($gui) Opt("GUIOnEventMode", 1) EndFunc Func RAMExit() Exit EndFunc ;--------------------------------------------------------------- ;- Enhanced Progress widget ;--------------------------------------------------------------- Func CreateProgress($x, $y, $w, $h, $Label="") Dim $Progress[2] $Progress[0] = GuiCtrlCreateProgress($x, $y, $w, $h) $Progress[1] = GuiCtrlCreateLabel($Label, $x, $y+3, $w, $h, $SS_CENTER ) GUICtrlSetBkColor($Progress[1], $GUI_BKCOLOR_TRANSPARENT) Return $Progress EndFunc Func UpdateProgress($ProgressID, $Percent, $Label="") GUICtrlSetData($ProgressID[0], $Percent) GUICtrlSetData($ProgressID[1], $Label & $Percent & "%") EndFunc ;--------------------------------------------------------------- ;- Reduce memory ;--------------------------------------------------------------- Func MemoryOptimize() $memory1 = MemGetStats ( ) Do ReduceMemory() $list = ProcessList() For $i=1 To $list[0][0] If StringInStr($list[$i][0], "csrss") > 0 Or StringInStr($list[$i][0], "smss") > 0 Or StringInStr($list[$i][0], "winlogon") > 0 Or StringInStr($list[$i][0], "lsass") > 0 Then ContinueLoop ReduceMemory($list[$i][1]) Next $memory2 = $memory1 $memory1 = MemGetStats ( ) Until $memory1[2] >= $memory2[2] EndFunc Func ReduceMemory($i_PID = -1) If $i_PID <> -1 Then Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID) Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0]) Else Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1) EndIf Return $ai_Return[0] EndFunc
RichardGatinho Posted January 24, 2007 Posted January 24, 2007 Hi. I have added ping-pong effect to avoid window maximizing, but with maximizing enabled. Ram.au3
d3mon Posted July 23, 2008 Posted July 23, 2008 Hi. I have added ping-pong effect to avoid window maximizing, but with maximizing enabled. Ram.au3 Hi, I've tried your script and I found it find so can you do function for "Unfreez" process andthe memory will be normal ^^ Thanks in advance ! No-life of autoit...what could be better ?LAST SCRIPTS WITH AUTO-IT : CLICK HERE
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now