JerichoJones Posted July 17, 2006 Posted July 17, 2006 The line in Bold/underline is where the problem lies.....Below is the code (it should be self explanatory):#include <GuiConstants.au3>Opt("GUIOnEventMode", 1)$main = GuiCreate("", 142, 110,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))$bDisable = GuiCtrlCreateButton("Disable ScreenSaver", 10, 40, 120, 30)$lScrWiz = GuiCtrlCreateLabel("ScreenSaver Wizard", 10, 10, 120, 20,$SS_SUNKEN + $SS_CENTER)$lEnable = GuiCtrlCreateLabel("ScreenSaver Disabled!" & @CRLF & @CRLF & "Close the application to re-enable the screen saver.", 10, 35, 120, 80, + $SS_CENTER)GUICtrlSetState($lEnable,$GUI_HIDE) ; the button is in hidden stateGUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")GUICtrlSetOnEvent($bDisable, "ScrDisable")$regScrnSaver = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE")GUISetState(@SW_SHOW)While 1 Sleep(1000) ; Idle aroundWEndFunc ScrDisable() $rc = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") If Not $rc = "" Then Do $rcd = RegDelete("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") Sleep(1000) Until $rcd = 1 EndIf GUICtrlSetState($bDisable,$GUI_HIDE) GUICtrlSetState($lEnable,$GUI_SHOW) Do $rc = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") If Not $rc = "" Then RegDelete("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") EndIf Sleep("1000") ;MsgBox(0,"",GUICtrlGetState($main)) Until GUICtrlGetState($main) = $GUI_EVENT_CLOSEEndFuncFunc CLOSEClicked() RegWrite("HKCU\Control Panel\Desktop","SCRNSAVE.EXE","REG_SZ", $regScrnSaver) ExitEndFunc
jvanegmond Posted July 17, 2006 Posted July 17, 2006 Until GUIGetMsg() = $GUI_EVENT_CLOSE github.com/jvanegmond
PsaltyDS Posted July 17, 2006 Posted July 17, 2006 The line in Bold/underline is where the problem lies..... Below is the code (it should be self explanatory): CODE#include <GuiConstants.au3> Opt("GUIOnEventMode", 1) $main = GuiCreate("", 142, 110,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $bDisable = GuiCtrlCreateButton("Disable ScreenSaver", 10, 40, 120, 30) $lScrWiz = GuiCtrlCreateLabel("ScreenSaver Wizard", 10, 10, 120, 20,$SS_SUNKEN + $SS_CENTER) $lEnable = GuiCtrlCreateLabel("ScreenSaver Disabled!" & @CRLF & @CRLF & "Close the application to re-enable the screen saver.", 10, 35, 120, 80, + $SS_CENTER) GUICtrlSetState($lEnable,$GUI_HIDE) ; the button is in hidden state GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlSetOnEvent($bDisable, "ScrDisable") $regScrnSaver = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") GUISetState(@SW_SHOW) While 1 Sleep(1000) ; Idle around WEnd Func ScrDisable() $rc = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") If Not $rc = "" Then Do $rcd = RegDelete("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") Sleep(1000) Until $rcd = 1 EndIf GUICtrlSetState($bDisable,$GUI_HIDE) GUICtrlSetState($lEnable,$GUI_SHOW) Do $rc = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") If Not $rc = "" Then RegDelete("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") EndIf Sleep("1000") ;MsgBox(0,"",GUICtrlGetState($main)) Until GUICtrlGetState($main) = $GUI_EVENT_CLOSE EndFunc Func CLOSEClicked() RegWrite("HKCU\Control Panel\Desktop","SCRNSAVE.EXE","REG_SZ", $regScrnSaver) Exit EndFunc That Do/Unitl loop is unecesary. Just put it in a While 1 loop. Your Until condition never gets to end the Do loop because when $GUI_EVENT_CLOSE happens, the CLOSEClicked() function will exit the script first. So: While 1 $rc = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") If Not $rc = "" Then RegDelete("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") EndIf Sleep("1000") ;MsgBox(0,"",GUICtrlGetState($main)) Wend Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
JerichoJones Posted July 17, 2006 Author Posted July 17, 2006 OK I have tried both suggestions yet when I click the X nothing happens. Minimize and maximize buttons work fine. I am at a loss as to what to try next.
GaryFrost Posted July 17, 2006 Posted July 17, 2006 expandcollapse popup#include <GuiConstants.au3> Opt("GUIOnEventMode", 1) $main = GUICreate("", 142, 110, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $bDisable = GUICtrlCreateButton("Disable ScreenSaver", 10, 40, 120, 30) $lScrWiz = GUICtrlCreateLabel("ScreenSaver Wizard", 10, 10, 120, 20, $SS_SUNKEN + $SS_CENTER) $lEnable = GUICtrlCreateLabel("ScreenSaver Disabled!" & @CRLF & @CRLF & "Close the application to re-enable the screen saver.", 10, 35, 120, 80, +$SS_CENTER) GUICtrlSetState($lEnable, $GUI_HIDE) ; the button is in hidden state GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlSetOnEvent($bDisable, "ScrDisable") $regScrnSaver = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") GUISetState(@SW_SHOW) While 1 Sleep(1000) ; Idle around WEnd Func ScrDisable() $rc = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") If Not $rc = "" Then $rcd = RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") Sleep(1000) EndIf GUICtrlSetState($bDisable, $GUI_HIDE) GUICtrlSetState($lEnable, $GUI_SHOW) $rc = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") If Not $rc = "" Then RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") EndIf Sleep("1000") EndFunc ;==>ScrDisable Func CLOSEClicked() RegWrite("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE", "REG_SZ", $regScrnSaver) Exit EndFunc ;==>CLOSEClicked SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
JerichoJones Posted July 24, 2006 Author Posted July 24, 2006 Func ScrDisable() $rc = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") If Not $rc = "" Then $rcd = RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") Sleep(1000) EndIf GUICtrlSetState($bDisable, $GUI_HIDE) GUICtrlSetState($lEnable, $GUI_SHOW) $rc = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") If Not $rc = "" Then RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") EndIf Sleep("1000") EndFunc ;==>ScrDisable OK. One thing I have determined is the If Not $rc = "" DOES NOT WORK. I had to change it to If $rc <> "" I wanted a While or Do here to ensure that if the Screen Saver GPO gets re-applied that it is immediately deleted. How can I pull that off and have it still respond to the CloseClicked? While 1 $rc = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") If Not $rc = "" Then RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") EndIf Sleep("1000") WEnd Thanks All! jj
MHz Posted July 24, 2006 Posted July 24, 2006 Your code is evaluating Not operator before the = operater as Not has a higher precedence. So Not is evaluating $rc 1st, and then the result is evalutated with the = "". Use braces as shown below, to force Not to evaluate $rc = "" result. Operator Precedence shown in helpfile.While 1 $rc = RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") If Not ($rc = "") Then RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") EndIf Sleep("1000") WEnd oÝ÷ Ù8^y«"zËfzØhv+0«r¢ë!£"¶¬xØ-ýº)z¶¢»¢ê Xç^½éí².Û-Y_·*'íéh¢¢÷«zZqçr¢êì©e)¶ëaz趦N½ç±¶¶¢wb¶*'zö¥¹«b¢x§¶¥¢HÂ¥uÚ"¶Øb³²{-y§ZºÚ"µÍÚ[HBRYYÔXY ][ÝÒÐÕIÌLÐÛÛÛ[[ ÌLÑÚÝÜ ][ÝË ][ÝÔÐÔÐUKVI][ÝÊH ÉÝÈ ][ÝÉ][ÝÈ[BTYÑ[]J ][ÝÒÐÕIÌLÐÛÛÛ[[ ÌLÑÚÝÜ ][ÝË ][ÝÔÐÔÐUKVI][ÝÊBQ[YTÛY ][ÝÌL ][ÝÊBÑ[
JerichoJones Posted July 24, 2006 Author Posted July 24, 2006 OK. Clicking X still does not respond nor does the value get deleted if it gets recreated. What am I doing wrong? Below is the updated code: #NoTrayIcon #include <GuiConstants.au3> Opt("GUIOnEventMode", 1) $main = GuiCreate("", 142, 110,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $bDisable = GuiCtrlCreateButton("Disable ScreenSaver", 10, 40, 120, 30) $lScrWiz = GuiCtrlCreateLabel("ScreenSaver Wizard", 10, 10, 120, 20,$SS_SUNKEN + $SS_CENTER) $lEnable = GuiCtrlCreateLabel("ScreenSaver Disabled!" & @CRLF & @CRLF & "Close this application to re-enable the screen saver.", 10, 35, 120, 80, + $SS_CENTER) GUICtrlSetState($lEnable,$GUI_HIDE) ; the button is in hidden state GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlSetOnEvent($bDisable, "ScrDisable") $regScrnSaver = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") GUISetState(@SW_SHOW) While 1 Sleep(1000) ; Idle around WEnd Func ScrDisable() $rc = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") If $rc <> "" Then Do $rcd = RegDelete("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") ;Sleep(1000) $rca = Regread("HKCU\Control Panel\Desktop","SCRNSAVE.EXE") Until $rca = "" EndIf GUICtrlSetState($bDisable,$GUI_HIDE) GUICtrlSetState($lEnable,$GUI_SHOW) While 1 If RegRead("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") <> "" Then RegDelete("HKCU\Control Panel\Desktop", "SCRNSAVE.EXE") EndIf Sleep("1000") WEnd EndFunc Func CLOSEClicked() RegWrite("HKCU\Control Panel\Desktop","SCRNSAVE.EXE","REG_SZ", $regScrnSaver) Exit EndFunc
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