caramen Posted December 28, 2018 Share Posted December 28, 2018 (edited) Well let's say first i got the jargon with registry french words. But i am not sure about english ones. I would like to improve my registry knowledge. I noticed i dont know how to check an existing key when she got no value inside it. I know with what i am saying now there is two cases possible but mine is this one : So if you can give me the correct english names for theses... I would say for the : Black square : KEY Blue square : Value Name Reg square : Value Type Now my issue. If i have a value name: Value1 with or without data set in it. I know how to check it. I just regread it and play with the return. But in this case i dont know how to get the "par défaut" value name if i try to regread it i am not successing. I dont know how to manage the return of it. I dont even now if this "par défaut" value name is existing or just a "virtual" data. or somthing. The goal is: Sometime I need to check the existence of an app(that mean the existence of the key) on a laptop but I always switch my method when i face this. But i like using the registry so if i can bypass that issue that would be cool . Edited December 28, 2018 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
kamiquasi Posted December 28, 2018 Share Posted December 28, 2018 If I'm reading this right, you're just trying to see if KEY exists, and don't necessarily care about the value of '(Default)'? If that is the case, you should check the @error value after using RegRead. Instead of specifying a value name, you can specify "" (which is what '(Default)' is referenced as, regardless of locale/language). ; Check if 'UserConfig' for 'MySoftware' exists and, if so, parse its '(Default)' value. Local $defaultValue = RegRead("HKCU\Software\MySoftware\UserConfig","") Local $errorRegRead = @error ConsoleWrite("Error: "&$errorRegRead&@CRLF) If ($errorRegRead == 0) Then ConsoleWrite("Value of (Default): "&$defaultValue&@CRLF) ElseIf ($errorRegRead > 0) Then ConsoleWrite("Key does not exist OR key could not be accessed OR key trunk could not be accessed"&@CRLF) ElseIf ($errorRegRead < 0) Then ConsoleWrite("Value name does not exist OR value s not set OR value can not be accessed"&@CRLF) EndIf If you do need to check for a specific value of '(Default)', you can perform the usual tests on $defaultValue to see if it's blank or some value when the @error is 0 (zero). The RegRead help has all this info, but this might make it easier to understand caramen and Subz 1 1 Link to comment Share on other sites More sharing options...
Subz Posted December 28, 2018 Share Posted December 28, 2018 I use the following udf, and RegKeyExists function as @kamiquasi points out you can test by using the @error return value. Func RegKeyExists($s_key) _RegRead($s_key, "") ; try to read default value Switch @error Case 1, 2 ; invalid root key | failed to open key Return SetError(@error, 0, 0) Case Else ; key exists Return SetError(0, 0, 1) EndSwitch kamiquasi and caramen 1 1 Link to comment Share on other sites More sharing options...
caramen Posted December 28, 2018 Author Share Posted December 28, 2018 Thanks guys yeah i was pretty stupid... It is just when we do somthing too much time we sometime forget to do the easyer thing first.... Totaly forget about using the @error flag... So obvius after reading it... Happy new year. kamiquasi 1 My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Subz Posted December 28, 2018 Share Posted December 28, 2018 No problem, happy new year to you as well. Link to comment Share on other sites More sharing options...
caramen Posted January 2, 2019 Author Share Posted January 2, 2019 (edited) On 28/12/2018 at 4:19 PM, kamiquasi said: If you do need to check for a specific value of '(Default)', you can perform the usual tests on $defaultValue to see if it's blank or some value when the @error is 0 (zero). The RegRead help has all this info, but this might make it easier to understand Or even @Subz When i try the following. I am not getting the defaut value i haven't the administrator right on this win session but i am reading current user registry so... test() Func test() $Regread = RegRead ( "HKEY_CURRENT_USER\Control Panel\Accessibility\On","") $Erreur = @extended If $Erreur = 1 Then MsgBox (0,"Erreur","Erreur 1 = unable to open requested key") If $Erreur = 2 Then MsgBox (0,"Erreur","Erreur 2 = unable to open requested main key") If $Erreur = 3 Then MsgBox (0,"Erreur","Erreur 3 = unable to remote connect to the registry") If $Erreur = -1 Then MsgBox (0,"Erreur","Erreur -1 = unable to open requested value") If $Erreur = -2 Then MsgBox (0,"Erreur","Erreur -2 = value type not supported") If $Erreur = 0 Then MsgBox (0,"Registre","Clef = "& $Regread ) $Erreur = 0 EndFunc Should post that with a switch to respect the exemple but well it's same... This is my return : Erreur 2 = unable to open requested main key This is my registry : Btw if i read Locale it is working. Edited January 2, 2019 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Subz Posted January 2, 2019 Share Posted January 2, 2019 It should be: $Erreur = @error @extended returns the registry type i.e. REG_SZ, REG_DWORD etc... Link to comment Share on other sites More sharing options...
caramen Posted January 2, 2019 Author Share Posted January 2, 2019 I dont know why it is working then . But I still cannot read this default value . What is it ? My syntax maybe? My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Subz Posted January 2, 2019 Share Posted January 2, 2019 (Default) is not an actual value and by default doesn't hold any data, you can see in your screenshot that (Default) has a value that has not been set. As mentioned above, if @error = 1 or 2 than the key doesn't exist, -1 or -2 result means the key exists, but their is an issue with the value i.e. it hasn't been set. Link to comment Share on other sites More sharing options...
caramen Posted January 3, 2019 Author Share Posted January 3, 2019 (edited) @Subz But the help file saying : To access the (Default) value use "" (an empty string) for the valuename. @Melba23 Does i am in special case for the second time ? Does the help file is again not updated ? Edited January 3, 2019 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Subz Posted January 3, 2019 Share Posted January 3, 2019 @caramen The help file is correct to access (Default) you need to use "", as mentioned (Default) does not normally have a value, I'm not sure what you're expecting to be returned, RegRead will return a blank value whether or not the key exists, which is why its better to use @error to determine if the key exists". Example \Off key below shouldn't exist, \On Key should exist, but blank value, and \Au3Info.exe should return the path to Au3Info.exe as the (Default) vaule has been set. ConsoleWrite(_RegKeyExists("HKCU\Control Panel\Accessibility\Off") & @CRLF) ConsoleWrite(_RegKeyExists("HKCU\Control Panel\Accessibility\On") & @CRLF) ConsoleWrite(_RegKeyExists("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Au3Info.exe") & @CRLF) Func _RegKeyExists($_sRegKey) Local $sDefault = RegRead($_sRegKey, "") ;~ Try to read default value Switch @error Case 1, 2 ;~ Unable to open requested key | Unable to open requested main key Return SetError(@error, 0, 'Error: Registry Key: "' & $_sRegKey & '" does not exist.') Case Else ; Registry Key Exists | Return (Default) value Return SetError(0, 0, $sDefault) EndSwitch EndFunc Link to comment Share on other sites More sharing options...
caramen Posted January 3, 2019 Author Share Posted January 3, 2019 (edited) @Subz Obviusly I dont understand somthing. But I have to figure out what is it. It is this : This sample : ConsoleWrite(RegRead ("HKCU\Control Panel\Accessibility\On","") & @CRLF) ConsoleWrite(RegRead ("HKCU\Control Panel\Accessibility\Off", "") & @CRLF) And this sample : ConsoleWrite(_RegKeyExists("HKCU\Control Panel\Accessibility\Off") & @CRLF) ConsoleWrite(_RegKeyExists("HKCU\Control Panel\Accessibility\On") & @CRLF) Func _RegKeyExists($_sRegKey) Local $sDefault = RegRead($_sRegKey, "") ;~ Try to read default value Switch @error Case 1, 2 ;~ Unable to open requested key | Unable to open requested main key Return SetError(@error, 0, 'Error: Registry Key: "' & $_sRegKey & '" does not exist.') Case Else ; Registry Key Exists | Return (Default) value Return SetError(0, 0, $sDefault) EndSwitch EndFunc Are same. The function does not change there is just an error checking added. But why : ;This: ConsoleWrite(_RegKeyExists("HKCU\Control Panel\Accessibility\On") & @CRLF) ;And This: ConsoleWrite(RegRead ("HKCU\Control Panel\Accessibility\On","") & @CRLF) Are not returning the same thing ? ;This Return an empty string: ConsoleWrite(_RegKeyExists("HKCU\Control Panel\Accessibility\On") & @CRLF) ;And This Return an error: (But an empty string in the console)(Corect me if i am false it is becose the error is here BUT the @CRLF = Empty string) ConsoleWrite(RegRead ("HKCU\Control Panel\Accessibility\On","") & @CRLF) Edited January 3, 2019 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Subz Posted January 3, 2019 Share Posted January 3, 2019 What error is it returning? It's returning a blank string for me. Link to comment Share on other sites More sharing options...
caramen Posted January 3, 2019 Author Share Posted January 3, 2019 (edited) (Corect me if i am false it is becose the error is here BUT the @CRLF = Empty string) Erreur 2 = unable to open requested main key Edited January 3, 2019 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
caramen Posted January 3, 2019 Author Share Posted January 3, 2019 (edited) I did a mistake. It is error -1. I think i got it now. Edited January 3, 2019 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
Subz Posted January 3, 2019 Share Posted January 3, 2019 As I've mentioned, (Default) normally doesn't have a value which is why value reads (value not set) or (valeur non definie) so it will return -1, if @error = 1 or 2 then the key doesn't exist. (Corect me if i am false it is becose the error is here BUT the @CRLF = Empty string) RegRead will return an empty string "" (not @CRLF) whether or not the key or value exists. However most people would check to see if a value exists as keys don't really have any value. As an example if I was going to roll our AutoIt 3.3.14.5 I'd use something like the following: nb: Find examples are easier to explain ;~ Check if AutoIt 3.3.14.5 is installed Local $bAutoItv3_3_14_5 = RegRead ("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\AutoItv3", "DisplayVersion") = "3.3.14.5" ? True : False ;~ Install AutoIt 3.3.14.5 if not found If $bAutoItv3_3_14_5 = False Then RunWait(@ScriptDir & "\autoit-v3-setup.exe -s") caramen 1 Link to comment Share on other sites More sharing options...
caramen Posted January 3, 2019 Author Share Posted January 3, 2019 (edited) 1 hour ago, Subz said: (Corect me if i am false it is becose the error is here BUT the @CRLF = Empty string) Yeah this was true with my mistake but false in the correct case. Edited January 3, 2019 by caramen My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki Link to comment Share on other sites More sharing options...
caramen Posted January 3, 2019 Author Share Posted January 3, 2019 Hey @Subz Thank you, you just learned me somthing. I never seen that kind of script. With "?" My video tutorials : ( In construction ) || My Discord : https://discord.gg/S9AnwHw How to Ask Help || UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote Spoiler Water's UDFs:Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - Wiki Tutorials:ADO - Wiki 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