JoaoCampos Posted April 13, 2007 Share Posted April 13, 2007 (edited) Hello all, ive made some gui interface where I have some fields thar write contents to an INI file, and in the script I use that values to make the script work, Well, when i change the fields and click in apply button I can save the data to ini file, but the script only use that values from the ini, in the next time I run the script. So... i need to close it after apply and run again the script I want something like -> On Apply button, save the data and reload the script to use the new values saved before. My Script is: expandcollapse popup#include <GUIConstants.au3> Opt('WintitleMatchmode',3) ;~ get vars from ini file $server = IniRead("dswatchdog.ini", "General", "Server", "NotFound") $port = IniRead("dswatchdog.ini", "General", "HttpPort", "NotFound") $watchtime = IniRead("dswatchdog.ini", "General", "WatchTime", "NotFound") $show = IniRead("dswatchdog.ini", "General", "Show", "NotFound") $guistate = IniRead("dswatchdog.ini", "General", "GuiState", "NotFound") $windowname = IniRead("dswatchdog.ini", "General", "WindowName", "NotFound") $browserpath = IniRead("dswatchdog.ini", "General", "BrowserPath", "NotFound") $regimodepath = IniRead("dswatchdog.ini", "General", "RegIEModePath", "NotFound") $regimodekey = IniRead("dswatchdog.ini", "General", "RegIEModeKey", "NotFound") $mousex = IniRead("dswatchdog.ini", "Mouse", "HideX", "NotFound") $mousey = IniRead("dswatchdog.ini", "Mouse", "HideY", "NotFound") $offlinetittle = $windowname&" - [Working Offline]" ;~ Some Var Concatenation $url = "http://"&$server&":"&$port&"/web/"&$show&"/index.php" $openshow = $browserpath&" "&$url Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form=c:\documents and settings\joão campos\desktop\aform1.kxf $aplicacao = GUICreate("Digital Spot Watch Dog 1.0b", 333, 619, 193, 115) $Groupshowinfo = GUICtrlCreateGroup("Show info", 8, 16, 313, 137) $serverlabel = GUICtrlCreateLabel("Server:", 24, 40, 38, 17) $portlabel = GUICtrlCreateLabel("Port:", 224, 40, 26, 17) $Inputserver = GUICtrlCreateInput($server, 24, 56, 169, 22) $Inputport = GUICtrlCreateInput($port, 224, 56, 73, 22) $showlabel = GUICtrlCreateLabel("Show:", 24, 96, 34, 17) $Inputshow = GUICtrlCreateInput($show, 24, 112, 169, 21) $watchtimelabel = GUICtrlCreateLabel("Watch Time (ms):", 224, 96, 87, 17) $Inputwatchtime = GUICtrlCreateInput($watchtime, 224, 112, 73, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $Groupbrowserinfo = GUICtrlCreateGroup("Browser Info", 8, 168, 313, 137) $windoenamelabel = GUICtrlCreateLabel("Window Name:", 24, 192, 77, 17) $Inputwindowname = GUICtrlCreateInput($windowname, 24, 208, 281, 21) $browserpathlabel = GUICtrlCreateLabel("Browser Path:", 24, 248, 70, 17) $Inputbrowserpath = GUICtrlCreateInput($browserpath, 24, 264, 281, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $Grouponlineoffline = GUICtrlCreateGroup("Online - Offline Mode", 8, 320, 313, 129) $rpathlabel = GUICtrlCreateLabel("Registry Path:", 24, 344, 70, 17) $rkeylabel = GUICtrlCreateLabel("Registry Key:", 24, 392, 66, 17) $Inputrpath = GUICtrlCreateInput($regimodepath, 24, 360, 281, 21) $Inputrkey = GUICtrlCreateInput($regimodekey, 24, 408, 281, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $quitnosavebtn = GUICtrlCreateButton("Exit without saving", 216, 560, 107, 25, 0) $applybtn = GUICtrlCreateButton("Apply ", 8, 560, 75, 25, 0) GUICtrlSetOnEvent($applybtn,"aplicar") $Groupmousecoordinates = GUICtrlCreateGroup("Hide Mouse Coordinates", 8, 464, 313, 81) $xcoordlabel = GUICtrlCreateLabel("X Coordinate", 24, 488, 65, 17) $ycoordlabel = GUICtrlCreateLabel("Y Coordinate", 184, 488, 65, 17) $Inputxcoord = GUICtrlCreateInput($mousex, 24, 504, 113, 21) $Inputyxoord = GUICtrlCreateInput($mousey, 184, 504, 113, 21) GUICtrlCreateGroup("", -99, -99, 1, 1) $File = GUICtrlCreateMenu("&File") $Exit = GUICtrlCreateMenuItem("Exit", $File) $MenuItem2 = GUICtrlCreateMenu("&Help") $MenuItem1 = GUICtrlCreateMenuItem("About", $MenuItem2) GUICtrlSetOnEvent($quitnosavebtn,"fechar") GUISetOnEvent($GUI_EVENT_CLOSE,"fechar") ; Read from ini file the state of gui window If $guistate = "1" Then GUISetState(@SW_SHOWMINNOACTIVE) ElseIf $guistate = "2" Then GUISetState(@SW_SHOWNORMAL) Elseif $guistate = "3" Then GUISetState(@SW_SHOWMINIMIZED) Else GUISetState(@SW_SHOWMINIMIZED) EndIf #EndRegion ### END Koda GUI section ### ;~ Delay to initiate the Script Action Sleep(3000) ;~ Start the show for the first time Run($openshow) While 1 ;~ TEST Server using ICMP protocol. $testserver = Ping($server ,6000) Sleep(5000) ; Check the online/offline state in registry $checkiemode = RegRead($regimodepath, $regimodekey) ;~ If server ping responds OK and, in the Registry Internet state is set to offline lets change to online mode If $testserver <> 0 And $checkiemode = 1 Then ;~ Close iexplore.exe process ProcessClose("iexplore.exe") ;~ Set Internet explorer to Online Mode RegWrite ( $regimodepath, $regimodekey, "REG_DWORD", "0" ) ;~ Lets start the show... now in online mode Run($openshow) ;~ If server ping dont responds and, in the Registry Internet state is set to Online... ElseIf $testserver = 0 And $checkiemode = 0 Then ;~ Close iexplore.exe process ProcessClose("iexplore.exe") ;~ Set Internet explorer to Offline Mode RegWrite ( $regimodepath, $regimodekey, "REG_DWORD", "1" ) ;~ Lets start the show... now in online mode Run($openshow) ElseIf WinExists($windowname) = 0 And WinExists($offlinetittle) = 0 Then ;~ Close iexplore.exe process ProcessClose("iexplore.exe") ;~ This time we dont set offline or online mode, lets wait for next loop to check it out ;~ Lets start the show... now in online mode Run($openshow) Else EndIf ;~ Function to hide mouse cursor MouseMove($mousex, $mousey) ;~ Wait 5000 ms until next loop Sleep($watchtime) WEnd Func aplicar() IniWrite("dswatchdog.ini", "General", "Server", GUICtrlRead($Inputserver)) IniWrite("dswatchdog.ini", "General", "HttpPort", GUICtrlRead($Inputport)) IniWrite("dswatchdog.ini", "General", "WatchTime", GUICtrlRead($Inputwatchtime)) IniWrite("dswatchdog.ini", "General", "Show", GUICtrlRead($Inputshow)) IniWrite("dswatchdog.ini", "General", "WindowName", GUICtrlRead($Inputwindowname)) IniWrite("dswatchdog.ini", "General", "BrowserPath", GUICtrlRead($Inputbrowserpath)) IniWrite("dswatchdog.ini", "General", "RegIEModePath", GUICtrlRead($Inputrpath)) IniWrite("dswatchdog.ini", "General", "RegIEModeKey", GUICtrlRead($Inputrkey)) IniWrite("dswatchdog.ini", "Mouse", "HideX", GUICtrlRead($Inputxcoord)) IniWrite("dswatchdog.ini", "Mouse", "HideY", GUICtrlRead($Inputyxoord)) GUISetState(@SW_SHOWMINIMIZED) EndFunc Func fechar() MsgBox(0,"Closing DS Watch Dog!", "You are closing DS Watch Dog. If you want to run it again, please do it mannualy.",30) Exit EndFunc My ini File is: [General] ; Server name and port Server=google.com HttpPort=80 ; Delay time until the next check WatchTime=2500 ; Name of the show Show=player ; Browser and window tittle WindowName=player - Windows Internet Explorer BrowserPath=c:\Program Files\Internet Explorer\iexplore.exe ; Path and Key in Registry RegIEModePath=HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings RegIEModeKey=GlobalUserOffline ; Gui state. 1-Hide 2-Maximided 3-Miminized GuiState=2 [Mouse] ; Coordenates for mouse hiding effect HideX=3000 HideY=3000 My best regards, João Campos Edited April 13, 2007 by JoaoCampos Link to comment Share on other sites More sharing options...
SadBunny Posted April 13, 2007 Share Posted April 13, 2007 Hello all, ive made some gui interface where I have some fields thar write contents to an INI file, and in the script I use that values to make the script work,Well, when i change the fields and click in apply button I can save the data to ini file, but the script only use that values from the ini, in the next time I run the script. So... i need to close it after apply and run again the script I want something like -> On Apply button, save the data and reload the script to use the new values saved before.You shouldn't have to reload the script. I think a better solution would be one of the following:1) Write the changes to ini AND apply them in the correct variables while the script is running,2) (I THINK BETTER:) Create a ReadAndApplyIni() function or something, and put all those IniRead commands in there. Then just run the function on script startup and on button press. Roses are FF0000, violets are 0000FF... All my base are belong to you. 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