;================================================================================ ; Description: Memory Fusion ; Author(s): mrbond007 (Baki G) & picasso (Fida Florian) ; Comments: Recover and Defragments the Memory ; And allows you to automaticlly recover the Memory ; ; Recover function belongs to W0uter ; ; Remember if you like AutoIt Donate to the AutoIt Project: ; http://www.autoitscript.com/donate.php ;================================================================================ #NoTrayIcon Opt("TrayMenuMode", 1) Opt("TrayOnEventMode", 1) Global Const $GUI_ENABLE = 64 Global Const $GUI_DISABLE = 128 Global Const $GUI_CHECKED = 1 Global Const $GUI_UNCHECKED = 4 Global Const $GUI_EVENT_CLOSE = -3 Global Const $GUI_EVENT_MINIMIZE = -4 Global $Button[4], $RamF, $fUpdateMeminfo = True, $MemStats = MemGetStats() $version = "Memory Fusion" If WinExists($version) Then Exit AutoItWinSetTitle($version) $RestoreItm = TrayCreateItem("Restore") TrayItemSetOnEvent(-1, "Restore_GUI") TrayItemSetState(-1, 512) ;$TRAY_DEFAULT TrayCreateItem("") $RecoverItm = TrayCreateItem("Recover") TrayItemSetOnEvent(-1, "RecoverMem") $DefragItm = TrayCreateItem("Defrag") TrayItemSetOnEvent(-1, "Defrag_Mem") TrayCreateItem("") $ExitItm = TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "Close") GUICreate("Memory Fusion", 350, 290) GUISetBkColor(0xEBEBEB) GUICtrlCreateGroup("Status", 5, 5, 340, 75) GUICtrlCreateGroup("Info", 5, 85, 340, 75) $Label1 = GUICtrlCreateLabel("100%", 310, 25, 30, 21) $Label2 = GUICtrlCreateLabel("100%", 310, 50, 30, 21) $Label3 = GUICtrlCreateLabel("", 90, 135, 55, 21) GUICtrlCreateLabel($MemStats[1] & "KB", 90, 110, 55, 20) $Label4 = GUICtrlCreateLabel("", 280, 110, 55, 20) $Label5 = GUICtrlCreateLabel("", 280, 135, 55, 20) GUICtrlCreateGraphic(85, 25, 210, 15) GUICtrlSetColor(-1, 0x000000) GUICtrlCreateGraphic(85, 50, 210, 15) GUICtrlSetColor(-1, 0x000000) GUICtrlCreateLabel("Used Memory", 10, 25, 75, 20) GUICtrlCreateLabel("Free Memory", 10, 50, 75, 20) GUICtrlCreateLabel("Total Memory", 10, 110, 75, 20) GUICtrlSetColor(-1, 0x0083C1) GUICtrlCreateLabel("Free Memory", 10, 135, 75, 20) GUICtrlSetColor(-1, 0x0083C1) GUICtrlCreateLabel("Used Memory", 195, 110, 75, 20) GUICtrlSetColor(-1, 0x0083C1) GUICtrlCreateLabel("Paging File", 195, 135, 75, 20) GUICtrlSetColor(-1, 0x0083C1) $ProgressB1 = GUICtrlCreateGraphic(86, 26, 0, 13) GUICtrlSetColor($ProgressB1, 0x000000) GUICtrlSetBkColor($ProgressB1, 0x0FB1FF) $ProgressB2 = GUICtrlCreateGraphic(86, 51, 0, 13) GUICtrlSetColor($ProgressB2, 0x000000) GUICtrlSetBkColor($ProgressB2, 0x0FB1FF) $Checked1 = GUICtrlCreateRadio("Automaticlly recover the pc memory when it's less than 10%", 5, 170, 300, 20) $Checked2 = GUICtrlCreateRadio("Automaticlly recover the pc memory when it's less than 20%", 5, 195, 300, 20) $Button[0] = GUICtrlCreateButton("Recover", 5, 255, 75, 25) $Button[1] = GUICtrlCreateButton("Defrag", 138, 255, 75, 25) $Button[2] = GUICtrlCreateButton("Exit", 270, 255, 75, 25) $Button[3] = GUICtrlCreateButton("Memory Stress Test", 5, 220, 340, 25) If @OSTYPE = "WIN32_WINDOWS" Then GUICtrlSetState($Checked1, $GUI_UNCHECKED) GUICtrlSetState($Checked1, $GUI_DISABLE) GUICtrlSetState($Checked2, $GUI_UNCHECKED) GUICtrlSetState($Checked2, $GUI_DISABLE) GUICtrlSetState($Button[0], $GUI_DISABLE) Else GUICtrlSetState($Checked1, $GUI_CHECKED) EndIf If StringInStr($CmdLineRaw, "/tray") Then Minimize_GUI(True) Else GUISetState() EndIf MonitorMem() AdlibEnable("MonitorMem", 500) While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_MINIMIZE Minimize_GUI() Case $Msg = $GUI_EVENT_CLOSE Or $Msg = $Button[2] Close() Case $Msg = $Button[0] RecoverMem() Case $Msg = $Button[1] PrepareToDefrag() Case $Msg = $Button[3] MemStressPrepare() EndSelect WEnd Func MonitorMem() If GUICtrlRead($Checked1) = $GUI_CHECKED Then Check_Condition_1() ElseIf GUICtrlRead($Checked2) = $GUI_CHECKED Then Check_Condition_2() EndIf $MemStats = MemGetStats() $RamF = Round(100 * ($MemStats[1] - $MemStats[2]) / $MemStats[1], 1) GUICtrlSetPos($ProgressB1, 86, 26, $RamF * 2.08, 13) GUICtrlSetData($Label1, $RamF & "%") $RamF = Round(100 * ($MemStats[2] / $MemStats[1]), 1) If $RamF < 1 Then GUICtrlSetPos($ProgressB2, 86, 51, 1, 13) Else GUICtrlSetPos($ProgressB2, 86, 51, $RamF * 2.08, 13) EndIf GUICtrlSetData($Label2, $RamF & "%") GUICtrlSetData($Label3, $MemStats[2] & "KB") $RamF = $MemStats[1] - $MemStats[2] GUICtrlSetData($Label4, $RamF & "KB") GUICtrlSetData($Label5, $MemStats[4]) EndFunc Func RecoverMem() $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 NtMem($list[$i][1]) Next EndFunc Func NtMem($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 EndFunc Func PrepareToDefrag() For $i = 0 To UBound($Button)-1 GUICtrlSetState($Button[$i], $GUI_DISABLE) Next ClipPut("") Defrag_Mem() EnvUpdate() If @OSTYPE == "WIN32_WINDOWS" Then GUICtrlSetState($Button[0], $GUI_DISABLE) Else GUICtrlSetState($Button[0], $GUI_ENABLE) EndIf For $i = 1 To UBound($Button)-1 GUICtrlSetState($Button[$i], $GUI_ENABLE) Next EndFunc Func Defrag_Mem() $MemStats = MemGetStats() If @OSTYPE == "WIN32_NT" Then Local $DllStruct = DllStructCreate("char[" & $MemStats[1] * 768 & "]") Sleep(7500) $DllStruct = "" ElseIf @OSTYPE == "WIN32_WINDOWS" Then Local $DllStruct = DllStructCreate("char[" & ($MemStats[1] * 512) & "]") Local $DllStruct2 = DllStructCreate("char[" & ($MemStats[1] * 512) & "]") Sleep(7500) $DllStruct = "" $DllStruct2 = "" EndIf EndFunc Func MemStressPrepare() For $i = 0 To UBound($Button)-1 GUICtrlSetState($Button[$i], $GUI_DISABLE) Next For $s = 1 To 3 MemStress($MemStats[2] * 32) MemStress($MemStats[2] * 64) MemStress($MemStats[2] * 128) MemStress($MemStats[2] * 256) MemStress($MemStats[2] * 320) MemStress($MemStats[2] * 256) MemStress($MemStats[2] * 128) MemStress($MemStats[2] * 64) MemStress($MemStats[2] * 32) Next If @OSTYPE == "WIN32_WINDOWS" Then GUICtrlSetState($Button[0], $GUI_DISABLE) Else GUICtrlSetState($Button[0], $GUI_ENABLE) EndIf For $i = 1 To UBound($Button)-1 GUICtrlSetState($Button[$i], $GUI_DISABLE) Next EndFunc Func MemStress($szMemAmount) Local $DllStruct = DllStructCreate("char[" & $szMemAmount & "]") Sleep(2000) $DllStruct = "" EndFunc Func Check_Condition_1() If 100 - $MemStats[0] < 10 Then RecoverMem() EndFunc Func Check_Condition_2() If 100 - $MemStats[0] < 20 Then RecoverMem() EndFunc Func Minimize_GUI($fStartup = False) $fUpdateMeminfo = False If Not $fStartup Then GUISetState(@SW_HIDE) TraySetState() AdlibDisable() EndFunc Func Restore_GUI() TraySetState(2) $fUpdateMeminfo = True GUISetState(@SW_SHOW) GUISetState(@SW_RESTORE) MonitorMem() AdlibEnable("MonitorMem", 500) EndFunc Func Close() Exit EndFunc