laphlaw Posted May 22, 2006 Share Posted May 22, 2006 I don't know if it's script-related, but it seems that whenever I run my GUI, my computer will start slowing down. Now I know this could be an infinite number of things, but it only seems to happen when I launch the GUI and use it for a while. It's like every 2 seconds, the computer will slightly pause... infact, it's happening as I type this. What doesn't make sense is that when I close the GUI and any script-related processes, it still continues until I log off or wait a while. This also happens to another person who is using the script. Is it my code that is affecting it? The script might not run correctly, but does it have to do with the way I'm polling the GUI? Thanks expandcollapse popup#include <GUIConstants.au3> #include <file.au3> Opt("TrayIconDebug",1) $CMSDir="C:\AutomationCMS" $username="Administrator" $password="000000" $CMSVersion="2.0.00.0003" $AutomationCMSVersion="1.0.00.0001" ;Creates the 'torun.ini' file in the script directory CreateTempIni(0) $serverIP="" ;=============================================================================== ;== Create Main GUI, tabs, File Menu ;=============================================================================== $GUI_Main=GUICreate("Automated Test Plan", 800, 400, 192, 125) GUICtrlCreateTab(8, 1, 775, 375) GUICtrlCreateTabItem("Server") $FileMenu = GUICtrlCreateMenu("&File") $HelpMenu = GUICtrlCreateMenu("&Help") $menu_About = GUICtrlCreateMenuitem ("About",$HelpMenu) $menu_EditIPs = GUICtrlCreateMenuitem ("Edit Server IPs",$FileMenu) $menu_EditSettings = GUICtrlCreateMenuitem ("Edit Settings",$FileMenu) $menu_ClearLog = GUICtrlCreateMenuitem ("Clear Log",$FileMenu) ;=============================================================================== ;== Create Tree, tree items ;=============================================================================== $serverlist = GUICtrlCreateTreeView(16, 35, 121, 320) $local=GUICtrlCreateTreeViewitem ("Local Machine",$serverlist) $1= GUICtrlCreateTreeViewitem ("Client 1",$serverlist) $2= GUICtrlCreateTreeViewitem ("Client 2",$serverlist) $3= GUICtrlCreateTreeViewitem ("Client 3",$serverlist) $4= GUICtrlCreateTreeViewitem ("Client 4",$serverlist) ;=============================================================================== ;== Create list boxes, populate the left list ;=============================================================================== $scriptlist = GUICtrlCreateList("", 316, 64, 145, 279) ListFiles();Add available scripts in the Exe directory $scriptstorun = GUICtrlCreateList("", 572, 64, 145, 279) ;=============================================================================== ;== Create GUI buttons ;=============================================================================== $b_addall = GUICtrlCreateButton("Add All", 470, 70, 80, 25) $b_removeall= GUICtrlCreateButton("Remove All", 470, 95, 80, 25) $b_add = GUICtrlCreateButton(">>", 492, 144, 43, 25) $b_remove = GUICtrlCreateButton("<<", 492, 184, 43, 25) $b_runselected= GUICtrlCreateButton("Run &Selected", 476, 250, 75, 25) $b_ping= GUICtrlCreateButton("P&ing Server", 150, 90, 75, 25) $b_processkill = GUICtrlCreateButton("&Kill Running Processes", 150, 315, 125, 25) $b_viewpic= GUICtrlCreateButton("View Live &Picture", 150, 280, 125, 25) ;------Add feature to be able to change picture size, toggle fade effect on/off, frequency of images taken, etc.-------; $b_viewlog= GUICtrlCreateButton("View &Log", 150, 120, 75, 25) ;=============================================================================== ;== Create labels, groups, and misc. items ;=============================================================================== GUICtrlCreateGroup("Remote Script Controls", 144, 258, 137, 95) GUICtrlCreateGroup("Hot Keys (local only)", 144, 165, 137, 75) GUICtrlCreateLabel("-Kill running script: Ctrl+C", 149, 185, 125, 17) GUICtrlCreateLabel("-Kill master script: Ctrl+M", 149, 205, 125, 17) $checkbox_loop = GUICtrlCreateCheckbox("Loop", 484, 304, 65, 17) GUICtrlCreateGroup("Available Scripts", 296, 48, 433, 305) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("Client Info", 144, 48, 137, 100) GUICtrlCreateGroup("", -99, -99, 1, 1) $label_serverip=GUICtrlCreateLabel("IP: ", 149, 72, 100, 17) ;=============================================================================== ;== Show main gui, click the tree highlight the first server ;=============================================================================== GUISetState(@SW_SHOW,$GUI_Main) ControlClick('Automated Test Plan','Add All',7) ;=================================================================================================== =========================================================== ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~GUI CODE STARTS BELOW~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;Note: ;==$array[0] = 0 or Event ID or Control ID ;==$array[1] = The window handle the event is from ;=================================================================================================== =========================================================== While 1 $msg = GuiGetMsg(1) Select ;=============================================================================== ;== Button: X, main GUI ;=============================================================================== Case $msg[0] = $GUI_EVENT_CLOSE and $msg[1]=$GUI_Main FileDelete($CMSDir & "\ToRun.ini") if @error then MsgBox(0,"Error","Error deleting temp file!") ProcessClose('LivePic.exe') ExitLoop ;=============================================================================== ;== Server tree ;=============================================================================== Case $msg[0]=$1 or $msg[0]=$2 or $msg[0]=$3 or $msg[0]=$4 or $msg[0]=$local ;~ MsgBox(0,'',GUICtrlRead($serverlist)) $sec=_CtrlIDtoSec(GUICtrlRead($serverlist));send the control ID and convert it to the readable section ;~ MsgBox(0,'',$sec) ;Get the client's IP $serverIP=IniRead($CMSDir & '\IP.ini',$sec,'IP','Not Found') GUICtrlSetData($label_serverip,"IP: " & $serverIP) ;=============================================================================== ;== Button: View Log ;=============================================================================== case $msg[0]=$b_viewlog $pos=WinGetPos('Automated Test Plan') $size=WinGetClientSize('Automated Test Plan') ToolTip('Loading Log...',$pos[0]+($size[0]/2),$pos[1]+($size[1]/2)) If $serverIP="Local Machine" Then If FileExists($CMSDir & '\WebLog\TestPlan.html')=0 Then ToolTip('') MsgBox(0,'Error', 'No existing log!') Else Run(@comSpec & ' /c ' & $CMSDir & '\WebLog\TestPlan.html', '', @SW_HIDE) ToolTip('') WinWaitActive("Test Plan Log") EndIf Else RunWait(@comSpec & ' /c net use \\' & $serverip & '\C$ /u:' & $username & ' ' & $password, '', @SW_HIDE) If FileExists('\\' & $serverip & '\C$\AutomationCMS\WebLog\TestPlan.html')=0 Then MsgBox(0,'Error', 'No existing log!') ToolTip('') Else Run(@comSpec & ' /c \\' & $serverip & '\C$\AutomationCMS\WebLog\TestPlan.html', '', @SW_HIDE) WinWaitActive("Test Plan Log") ToolTip('') EndIf EndIf ;=============================================================================== ;== Button: View Live Picture ;=============================================================================== case $msg[0]=$b_viewpic if not ProcessExists('LivePic.exe') Then Run($CMSDir & '\LivePic.exe ' & $serverIP) GUICtrlSetData($b_viewpic,"Disable Live Picture") Else ProcessClose('LivePic.exe') GUICtrlSetData($b_viewpic,"View Live Picture") EndIf ;=============================================================================== ;== Button: Run Selected ;=============================================================================== Case $msg[0]=$b_runselected If $serverIP="" Then MsgBox(0,"Select Server!", "First select a server on the tree!") Else $pos=WinGetPos('Automated Test Plan') $size=WinGetClientSize('Automated Test Plan') ToolTip('Please Wait...',$pos[0]+($size[0]/2),$pos[1]+($size[1]/2)) ;=============================================================; Select ;----------------------------------------- ;-----------Local Exection---------------- ;----------------------------------------- Case $serverIP="Local Machine" ;Install files/folders, if necessary If FileExists($CMSDir & "\WebLog")=0 Then DirCreate($CMSDir & "\WebLog\MasterScreenshots") DirCreate($CMSDir & "\WebLog\CapturedScreenshots") DirCreate($CMSDir & "\WebLog\PerformanceLogs") EndIf ;Check for local nic card settings If IniRead(@ScriptDir & '\IP.ini','Local Machine','nic','Not Found') = "" Then ToolTip('') MsgBox(0,"Attention","Nic card settings for performance monitoring not set... please wait", 5) GetNic() $nic=IniRead($CMSDir & '\IP.ini',$sec,'nic','Not Found') IniWrite($CMSDir & "\torun.ini", "NIC", "Value", $nic) MsgBox(0, "Done", "NIC card settings retrieved. Please select your script to run. You will not see this message again.") EndIf ;-------------looped--------------- if GUICtrlRead($checkbox_loop)=$GUI_CHECKED Then ToolTip('') ;case guiprep hasn't been run if IniRead($CMSDir & '\ToRun.ini', 'GUIPrep','Ready','Not Found') <> 'Yes' then $choice=MsgBox(4,'Run GUIPrep?', 'The "GUIPrep" function has not been run yet. Running a script without first preparing the GUI will likely cause the script to fail. Run GUIPrep?') If $choice=6 Then RunWait($CMSDir & '\GUIPrep.exe') IniWrite($CMSDir & "\torun.ini", "GUIPrep", "Ready", "Yes") RunWait($CMSDir & '\LocalMaster.exe "loop" "' & $sec & '"') Else $nic=IniRead($CMSDir & '\IP.ini',$sec,'nic','Not Found') IniWrite($CMSDir & "\torun.ini", "NIC", "Value", $nic) RunWait($CMSDir & '\LocalMaster.exe "loop" "' & $sec & '"') EndIf EndIf EndIf ;------------not looped---------------- if GUICtrlRead($checkbox_loop)=$GUI_UNCHECKED Then ToolTip('') ;case guiprep hasn't been run if IniRead($CMSDir & '\ToRun.ini', 'GUIPrep','Ready','Not Found') <> 'Yes' then $choice=MsgBox(4,'Run GUIPrep?', 'The "GUIPrep" function has not been run yet. Running a script without first preparing the GUI will likely cause the script to fail. Run GUIPrep?') If $choice=6 Then RunWait($CMSDir & '\GUIPrep.exe') IniWrite($CMSDir & "\torun.ini", "GUIPrep", "Ready", "Yes") RunWait($CMSDir & '\LocalMaster.exe "NoLoop" "' & $sec & '"') Else $nic=IniRead($CMSDir & '\IP.ini',$sec,'nic','Not Found') IniWrite($CMSDir & "\torun.ini", "NIC", "Value", $nic) RunWait($CMSDir & '\LocalMaster.exe "NoLoop" "' & $sec & '"') EndIf EndIf EndIf ;----------------------------------------- ;-----------Remote Exection---------------- ;----------------------------------------- Case Else if GUICtrlRead($checkbox_loop)=1 Then $nic=IniRead($CMSDir & '\IP.ini',$sec,'nic','Not Found') IniWrite($CMSDir & "\torun.ini", "NIC", "Value", $nic) FileDelete('\\' & $serverip & '\c$\AutomationCMS_0003\Exe\*.exe') ;Delete previous exes RunSelected($serverip,"loop") Else $nic=IniRead($CMSDir & '\IP.ini',$sec,'nic','Not Found') IniWrite($CMSDir & "\torun.ini", "NIC", "Value", $nic) FileDelete('\\' & $serverip & '\c$\' & $CMSDir & '\Exe\*.exe') RunSelected($serverip,"") EndIf ToolTip('') EndSelect EndIf ;=============================================================; ;=============================================================================== ;== Add button functions ;=============================================================================== case $msg[0]=$b_add $selectedscript=GUICtrlRead($scriptlist) IniWrite($CMSDir & "\torun.ini",$selectedscript & ".exe","Run","1") GUICtrlSetData($scriptstorun,$selectedscript) ;=============================================================================== ;== Remove Button functions ;=============================================================================== case $msg[0]=$b_remove $selectedscript=GUICtrlRead($scriptstorun) IniWrite($CMSDir & "\torun.ini",$selectedscript & ".exe","Run","0") GUICtrlSetData($scriptstorun,"") $sections=IniReadSectionNames($CMSDir & "\torun.ini") for $i=1 to $sections[0] if IniRead($CMSDir & "\torun.ini",$sections[$i],"Run","Not found")=1 Then GUICtrlSetData($scriptstorun,StringTrimRight($sections[$i],4)) EndIf Next ;=============================================================================== ;== Add all button functions ;=============================================================================== case $msg[0]=$b_addall $GUIPrepStatus=IniRead($CMSDir & "\ToRun.ini", "GUIPrep", "Ready", "Not Found") FileDelete($CMSDir & "\ToRun.ini") if @error then MsgBox(0,"Error","Error deleting temp file!") CreateTempIni(1) IniWrite($CMSDir & "\ToRun.ini", "GUIPrep", "Ready", $GUIPrepStatus) $files=_FileListToArray($CMSDir & "\Exe", "*.exe",1) for $i=1 to $files[0] GUICtrlSetData($scriptstorun,StringTrimRight($files[$i],4)) Next ;=============================================================================== ;== Remove all button functions ;=============================================================================== case $msg[0]=$b_removeall $GUIPrepStatus=IniRead($CMSDir & "\ToRun.ini", "GUIPrep", "Ready", "Not Found") FileDelete($CMSDir & "\ToRun.ini") if @error then MsgBox(0,"Error","Error deleting temp file!") CreateTempIni(0) IniWrite($CMSDir & "\ToRun.ini", "GUIPrep", "Ready", $GUIPrepStatus) GUICtrlSetData($scriptstorun,"") ;=============================================================================== ;== Button: Ping ;=============================================================================== Case $msg[0]=$b_ping $pos=WinGetPos('Automated Test Plan') $size=WinGetClientSize('Automated Test Plan') ToolTip('Please Wait...',$pos[0]+($size[0]/2),$pos[1]+($size[1]/2)) $sec=_CtrlIDtoSec(GUICtrlRead($serverlist)) $serverIP=IniRead($CMSDir & '\IP.ini',$sec,'IP','Not Found') $testonline=Ping($serverIP) if $testonline then ToolTip('') MsgBox(0,'Success',$sec & ' is online!') Else ToolTip('') Msgbox(0,"Error","Server unreachable. Either the server is offline, application is not running, or IPSec is on.") EndIf ;=============================================================================== ;== Button: Kill Processes ;=============================================================================== case $msg[0]=$b_processkill Run(@comSpec & ' /c psexec \\' & $serverIP & ' -u ' & $username & ' -p ' & $password & ' -i -d C:\' & $CMSDir & '\ProcessKill.exe') ;=============================================================================== ;== Menu Item: Edit IPs ;=============================================================================== case $msg[0]=$menu_EditIPs Run("notepad " & $CMSDir & "\IP.ini") ;=============================================================================== ;== Menu Item: Edit Settings ;=============================================================================== Case $msg[0]=$menu_EditSettings Run("notepad " & $CMSDir & "\Settings.ini") ;=============================================================================== ;== Menu Item: About ;=============================================================================== Case $msg[0]=$menu_About MsgBox(0,"Automated Test Plan", "CMS Version: " & $CMSVersion & @CRLF & @crlf & "AutomationCMS: " & $AutomationCMSVersion) ;=============================================================================== ;== Menu Item: About ;=============================================================================== Case $msg[0]=$menu_ClearLog $ClearLog=MsgBox(4, 'Clear Log?', 'Are you sure?') If $ClearLog=6 Then FileDelete($CMSDir & "\WebLog\*.html") FileDelete($CMSDir & "\WebLog\CapturedScreenshots\*.*") FileDelete($CMSDir & "\WebLog\PerformanceLogs\*.*") EndIf EndSelect WEnd Exit ;=============================================================================== ;== Functions ;=============================================================================== Func _CtrlIDtoSec($nID) ;The control ID can change, so be aware!! Select case $nID=12 $sec='Local Machine' case $nID=13 $sec='Client 1' case $nID=14 $sec='Client 2' case $nID=15 $sec='Client 3' case $nID=16 $sec='Client 4' EndSelect Return $sec EndFunc Func ListFiles() $filelist = _FileListToArray ($CMSDir & "\Exe", "*.exe", 1); list files to an array. If (Not IsArray($filelist)) Or (@error = 1) Then MsgBox(262208, "Error", "No Files\Folders Found. ", 5) Return EndIf GUICtrlSetData($filelist, ""); set list to empty. For $x = 1 To $filelist[0]; for loop to place the files in the list. GUICtrlSetData($scriptlist, (StringTrimRight($filelist[$x], 4)) & "|", 1); string trim the last 4 characters ( .exe ) Next EndFunc Func RunSelected($ip,$parameter) RunWait(@comSpec & ' /c net use \\' & $ip & '\C$ /u:' & $username & ' ' & $password,'', @SW_HIDE);this could be screwing it up ;~;Install files/folders, if necessary if FileExists("\\" & $ip & "\C$\" & $CMSDir)=0 then DirCreate("\\"& $ip & "\C$\" & $CMSDir & "\WebLog\MasterScreenshots") if @error then MsgBox(0,'Error','Error creating directory. Error: ' & @error) DirCreate("\\"& $ip & "\C$\" & $CMSDir & "\WebLog\CapturedScreenshots") DirCreate("\\"& $ip & "\C$\" & $CMSDir & "\WebLog\PerformanceLogs") DirCreate("\\"& $ip & "\C$\" & $CMSDir & "\EXE") EndIf ;Install a fresh copy of master, processkill, and screencapture every time FileCopy($CMSDir & "\Master.exe", "\\" & $ip & "\C$\AutomationCMS\",1) if @error then MsgBox(0,'Error','Error copying master.exe. Error: ' & @error) EndIf FileCopy($CMSDir & "\ProcessKill.exe", "\\" & $ip & "\C$\AutomationCMS\",1) if @error then MsgBox(0,'Error','Error copying ProcessKill.exe. Error: ' & @error) EndIf FileCopy($CMSDir & "\ScreenCapture.exe", "\\" & $ip & "\C$\AutomationCMS\",1) if @error then MsgBox(0,'Error','Error copying ScreenCapture.exe. Error: ' & @error) EndIf ;Delete any previous exes on the remote machine FileDelete("\\" & $ip & "\C$\AutomationCMS\Exe\*.exe") ;Reads which ones are "on", and copies those to the specified IP address $sections=IniReadSectionNames($CMSDir & "\ToRun.ini") for $i=1 to $sections[0] if IniRead($CMSDir & "\ToRun.ini",$sections[$i],"Run","Not Found")=1 then FileCopy($CMSDir & '\EXE\' & $sections[$i] ,'\\' & $ip & '\c$\AutomationCMS\Exe\',1) EndIf Next ;Call the master script and pass it a parameter to loop or not RunWait(@comSpec & ' /c psexec \\' & $ip & ' -u ' & $username & ' -p ' & $password & ' -i -d C:\AutomationCMS\Master.exe ' & $parameter) ;~ RunWait(@comSpec & ' /c net use \\' & $serverip & '\C$ /delete', '', @SW_HIDE) EndFunc Func CreateTempIni($iOnOff) ;Read the Exe directory for available scripts to an array $files=_FileListToArray($CMSDir & "\EXE\", "*.*",1) for $i=1 to $files[0] $files[$i]="[" & $files[$i] & "]" & @CRLF & "Run=" & $iOnOff Next ;Write them to an array for $i=1 to $files[0] FileWriteLine($CMSDir & "\ToRun.ini",$files[$i] & @CRLF & @CRLF) Next ;Set default that GUIPrep hasn't been run FileWriteLine($CMSDir & "\ToRun.ini", "[GUIPrep]" & @CRLF) FileWriteLine($CMSDir & "\ToRun.ini", "Ready=No" & @CRLF & @CRLF) ;Returns an array of all the sections in the ini $sections=IniReadSectionNames($CMSDir & "\ToRun.ini") if @error then return MsgBox(0,'Error','Unable to read ini sections to an array. Error: ' & @error) EndFunc Func GetNic() Run("perfmon") WinWaitActive("Performance") ControlClick("Performance", "", 1000) Send("^e") Sleep(500) Send("^i") WinWaitActive("Add Counters") ControlClick("Add Counters", "", "ComboBox3") Sleep(1000) Send("Network{enter}") ControlClick("Add Counters", "", "Add") ControlClick("Add Counters", "", "Close") WinWaitActive("Performance") Send("^c") $text=ClipGet() $file=FileOpen($CMSDir & "\nic.txt", 1) FileWrite($file, $text) FileClose($file) Run("notepad " & $CMSDir & "\nic.txt") WinWaitActive("nic") Send("^f") WinWaitActive("Find") Send("Interface{enter}") Send("{esc}") WinWaitActive("nic") Send("{right}") Send("{SHIFTDOWN}{END}{CTRLDOWN}{LEFT}{CTRLUP}{left 8}{shiftup}") Send("^c") $nic=ClipGet() IniWrite($CMSDir & '\IP.ini','Local Machine', 'nic', $nic) WinClose("nic") WinClose("Performance") FileDelete($CMSDir & "\nic.txt") EndFunc Link to comment Share on other sites More sharing options...
Valuater Posted May 23, 2006 Share Posted May 23, 2006 (edited) 1 I think alot of your problem lies within ;=============================================================================== ;== Button: Run Selected ;=============================================================================== Case $msg[0] = $b_runselected ..................... to ;=============================================================================== ;== Add button functions ;=============================================================================== Case $msg[0] = $b_add try using #cs and #ce to block tht section out... and see if that helps also in that section there actually should be a while / wend loop to keep that section running faster when called also in that section there are way to many regread & regwrites this happens over and over if the box is read as checked/unchecked also in that section... this cant be right If IniRead(@ScriptDir & '\IP.ini', 'Local Machine', 'nic', 'Not Found') = "" Then either you are writing "" to the file or you are getting the default you put "Not Found" just a quick look hope it helps 8) Edited May 23, 2006 by Valuater Link to comment Share on other sites More sharing options...
Uten Posted May 24, 2006 Share Posted May 24, 2006 I would add a check for $msg[0] = 0 at the top of the msg loop and a Case Else at the bottom.99% of the time there is nothing to do ( $msg[0] = 0 ) so there is no need to do all the other checks.Select Case $msg[0] = 0 sleep(100) ;Experiment with this, you might not need it. ; --- your code --- Case Else LogMsg("Unhandled $msg[0]:=" & $msg[0]);TODO: Your way of logging or disable. EndSelectI would also check cpu load and time in TaskManager (CTRL+SHIFT+ESC on w2k/XP) when this script runs as an executable. If your on a win9x system I would download Process Explorer from Sysinterals to get the same information. Now to the closing down part. I have experienced slow close downs but not hanging scripts except when I have goofed Usualy It solves itselfe when I place a few trace points in the script. To trace executables I use debug view also from sysinternals and som code like this.Func Tracedbg($msg) If @Compiled Then ; SOURCE: http://www.autoitscript.com/forum/index.php?showtopic=6617&st=0&p=46080&#entry46080 ; KUDOS: @tuape DllCall("kernel32.dll", "none", "OutputDebugString", "str", $msg) Else ConsoleWrite($msg) Endif EndFuncWish you a happy bug hunt Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
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