Colyn1337 Posted September 9, 2013 Share Posted September 9, 2013 (edited) This code loads the result of a regread into a variable and then parses the result: $RegResult = RegRead($HKLM & "\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters", "AutoShareWks") Select Case $RegResult = "" $RegWriteResult = RegWrite($HKLM & "\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters", "AutoShareWks", "REG_DWORD", "0") TrayTip("Registry Read", "AutoShareWks Reg key not found and was created. The read result was: " & $RegResult & " " & @error & _ ". The write result was: " & $RegWriteResult & " " & @error, 5) Case $RegResult = "0" ; 0 indicates sharing is off TrayTip("Registry Read", "Auto Drive Sharing is currently DISABLED.", 5) Case $RegResult = "1" ; 1 indicates sharing is on TrayTip("Registry Read", "Auto Drive Sharing is currently ENABLED", 5) EndSelect The problem is that the value of AutoShareWks is boolean and either 1 or 0. The documentation for regread states that if failure of the regread, "" is returned. However it seems to also interpret 0 as "" and trigger a false failure. Even @error has the same issue. If the reading value is 0, @error will trigger. So, how can I get around this false failure trigger? EDIT: I figured out a work around like this: $RegResult = RegRead($HKLM & "\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters", "AutoShareWks") Select Case $RegResult = "0" ; 0 indicates sharing is off TrayTip("Registry Read", "Auto Drive Sharing is currently DISABLED.", 5) Case $RegResult = "1" ; 1 indicates sharing is on TrayTip("Registry Read", "Auto Drive Sharing is currently ENABLED.", 5) Case Else ; Default Actions TrayTip("Registry Read", "AutoShareWks value not present in registry. Auto Drive Sharing is currently ENABLED.", 5) EndSelect However, still....... Why is the error process not catching it correctly? Edited September 9, 2013 by Colyn1337 Link to comment Share on other sites More sharing options...
mikell Posted September 9, 2013 Share Posted September 9, 2013 This works for me ; this regkey value is 0 $key = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Avidemux 2.5", "MementoSection_SecLangGerman") If $key = "" Then If @error Then msgbox(0,"", "failure") Else msgbox(0,"", "value = 0") EndIf EndIf Link to comment Share on other sites More sharing options...
sahsanu Posted September 10, 2013 Share Posted September 10, 2013 This code loads the result of a regread into a variable and then parses the result: $RegResult = RegRead($HKLM & "\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters", "AutoShareWks") Select Case $RegResult = "" $RegWriteResult = RegWrite($HKLM & "\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters", "AutoShareWks", "REG_DWORD", "0") TrayTip("Registry Read", "AutoShareWks Reg key not found and was created. The read result was: " & $RegResult & " " & @error & _ ". The write result was: " & $RegWriteResult & " " & @error, 5) Case $RegResult = "0" ; 0 indicates sharing is off TrayTip("Registry Read", "Auto Drive Sharing is currently DISABLED.", 5) Case $RegResult = "1" ; 1 indicates sharing is on TrayTip("Registry Read", "Auto Drive Sharing is currently ENABLED", 5) EndSelect The problem is that the value of AutoShareWks is boolean and either 1 or 0. The documentation for regread states that if failure of the regread, "" is returned. However it seems to also interpret 0 as "" and trigger a false failure. Even @error has the same issue. If the reading value is 0, @error will trigger. So, how can I get around this false failure trigger? You are trying to compare a Number and a String in your Case statements so you have two solutions (maybe more ;-)): Compare numbers (remove ""): Case $RegResult = 0 ; 0 indicates sharing is off TrayTip("Registry Read", "Auto Drive Sharing is currently DISABLED.", 5) Case $RegResult = 1 ; 1 indicates sharing is on TrayTip("Registry Read", "Auto Drive Sharing is currently ENABLED", 5) Compare strings (use == instead of =): Case $RegResult == "0" ; 0 indicates sharing is off TrayTip("Registry Read", "Auto Drive Sharing is currently DISABLED.", 5) Case $RegResult == "1" ; 1 indicates sharing is on TrayTip("Registry Read", "Auto Drive Sharing is currently ENABLED", 5) Take a look to Language Reference - Operators I hope this helps. Cheers, sahsanu 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