mark2 Posted April 16, 2016 Posted April 16, 2016 Hi, When i run my script, ram keep increasing every second which is 1mb/s and it up to 1gb after using around 10-15min. any suggestion for my below script please to stop the ram keep increasing ? thanks in advance. expandcollapse popup#RequireAdmin #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPIDiag.au3> #include <TrayConstants.au3> #include <MsgBoxConstants.au3> If NOT CheckConnect() Then TrayTip("","No Connection, Unable to start this application",5) Exit EndIf ProgressOn("", "Loading....", "0 percent") For $i = 5 To 100 Step 5 Sleep(100) ProgressSet($i, $i & " percent") Next ProgressSet(100, "Done", "Complete") Sleep(500) ProgressOff() Global Const $destination = "..\Pictures\earthshaker-guardian-of-the-red-mountain-wallpaper.jpg" Global Const $width = 500 Global Const $height = 400 Global Const $centerX = (@DesktopWidth - $width) / 2 Global Const $centerY = (@DesktopHeight - $height) / 2 SplashImageOn("", $destination, $width, $height, $centerX, $centerY, 2) Sleep(3000) SplashOff() Opt("TrayOnEventMode", 1) Opt("TrayMenuMode", 3) $tray = TrayCreateItem("Show") TrayItemSetOnEvent(-1, "To_Tray") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "On_Exit") $result = x("","") Local $IP = @IPAddress1 Local $MACAddress = _GetMACFromIP($result[0]) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 611, 120, 192, 124) $Label1 = GUICtrlCreateLabel("IP Address", 32, 8, 55, 17) $Label2 = GUICtrlCreateLabel("Default Gateway", 32, 48, 90, 17) $Label3 = GUICtrlCreateLabel("Router MAC Add", 32, 88, 83, 17) $Label4 = GUICtrlCreateLabel(""&$IP&"", 144, 8, 116, 17) $Label5 = GUICtrlCreateLabel(""&$result[0]&"", 144, 48, 116, 17) $Label6 = GUICtrlCreateLabel(""&$MACAddress&"", 144, 88, 116, 17) $Button1 = GUICtrlCreateButton("Close", 520, 72, 81, 33) $Checkbox1 = GUICtrlCreateCheckbox("Check If Want to set Startup", 280, 72, 170, 33) GUISetState(@SW_HIDE) If RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run", "AUTO") then GUICtrlSetData($CheckBox1, 'Added to Start up') GUICtrlSetState($Checkbox1,$GUI_CHECKED) EndIf #EndRegion ### END Koda GUI section ### ;If RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run", "AUTO") then ; $msgbox = MsgBox(4,"","Delete startup ?") ; if $msgbox = 6 Then ; RemoveStartup() ; EndIf ;Else ; $msgbox = MsgBox(4,"Start UP", "Do you want to add this applicaton to run as startup ?") ; If $msgbox = 6 Then ; AddStartup() ; EndIf ;EndIf $comand=" /c arp " $comand=$comand&$result[0]&" -g>D:\ORIGINAL.txt" $cmd = Run(@Comspec & $comand, "", @SW_HIDE) $comand=" /c arp " $comand=$comand&$result[0]&" -g>D:\UPDATE.txt" While 1 $cmd = Run(@Comspec & $comand, "", @SW_HIDE) While ProcessExists($cmd) Sleep(100) WEnd ;Local $time ;Sleep($time) $file=FileOpen("D:\Update.txt",0) $first=FileReadLine($file, 4) $first=StringTrimRight($first,15) $first=StringTrimLeft($first,24) $file=FileClose("D:\Update.txt") $file2=FileOpen("D:\ORIGINAL.txt",0) $second=FileReadLine($file2, 4) $second=StringTrimRight($second,15) $second=StringTrimLeft($second,24) $file2=FileClose("D:\ORIGINAL.txt") If CheckConnect() Then If $first=$second Then $time=5000 Else TrayTip("", "MAC Address was changed from "&$second&" to "&$first&". Trying to resolving",10) $comand=" /c netsh -c ""interface ipv4"" set neighbors "&$result[1]&" "&$result[0]&" "&$second&"" $cmd = Run(@Comspec & $comand, "", @SW_HIDE) While ProcessExists($cmd) sleep ($time) WEnd $comand=" /c arp " $comand=$comand&$result[0]&" -g>D:\UPDATE.txt" $time=2000 Sleep(5000) If $first=$second Then TrayTip("", "MAC has been fixed to "&$second&" ",5) EndIf EndIf Else TrayTip("","Your Connection has been lost, exit in 5 seconds",5) FileDelete("D:\UPDATE.txt") FileDelete("D:\ORIGINAL.txt") Run('netsh interface ip delete arpcache',"",@SW_HIDE) Exit EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $CheckBox1 If IsChecked($CheckBox1) Then GUICtrlSetData($CheckBox1, 'Added to Start up') AddStartup() Else GUICtrlSetData($CheckBox1, 'Check If Want to set Startup') RemoveStartup() EndIf Case $GUI_EVENT_CLOSE, $Button1 FileDelete("D:\UPDATE.txt") FileDelete("D:\ORIGINAL.txt") Run('netsh interface ip delete arpcache',"",@SW_HIDE) Exit Case $GUI_EVENT_MINIMIZE To_Tray() EndSwitch WEnd Func x ($DefaultGateway, $NetConnectionID) Local $array[2], $New_DefaultGateway, $New_NetConnectionID $Services = ObjGet("winmgmts:\\.\root\CIMV2") $NACs = $Services.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True') For $NAC In $NACs $NAs = $Services.ExecQuery('SELECT * FROM Win32_NetworkAdapter') For $NA In $NAs If $NA.MACAddress = $NAC.MACAddress Then $New_DefaultGateway = $NAC.DefaultIPGateway(0) $New_NetConnectionID = $NA.NetConnectionID $array[0] = $New_DefaultGateway $array[1] = $New_NetConnectionID Return $array Exitloop 2 EndIf Next Next EndFunc Func AddStartup() RegWrite("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run", "AUTO", "REG_SZ", @AutoItExe) EndFunc Func RemoveStartup() RegDelete("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run", "AUTO") EndFunc Func IsChecked($control) Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED EndFunc Func _GetMACFromIP($sIP) Local $MAC, $MACSize Local $i, $s, $r, $iIP $MAC = DllStructCreate("byte[6]") $MACSize = DllStructCreate("int") DllStructSetData($MACSize, 1, 6) $r = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $sIP) $iIP = $r[0] $r = DllCall("iphlpapi.dll", "int", "SendARP", "int", $iIP, "int", 0, "ptr", DllStructGetPtr($MAC), "ptr", DllStructGetPtr($MACSize)) $s = "" For $i = 0 To 5 If $i Then $s &= ":" $s = $s & Hex(DllStructGetData($MAC, 1, $i + 1), 2) Next Return $s EndFunc Func CheckConnect() $Status = DllCall("WinInet.dll", "int", "InternetGetConnectedState", "int_ptr", 0, "int", 0) Return $Status[0] EndFunc Func To_Tray() If TrayItemGetText($tray) = "Hide" Then GUISetState(@SW_HIDE, $Form1) TrayItemSetText($tray, "Show") Else GUISetState(@SW_SHOW, $Form1) GUISetState(@SW_RESTORE, $Form1) TrayItemSetText($tray, "Hide") EndIf EndFunc Func On_Exit() Exit EndFunc
AutoBert Posted April 16, 2016 Posted April 16, 2016 Add Local in your funcs when declaring and 1. assign of a variable. For variables of type object free the used objects by assigning 0 to this vars before returning.
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