ViciousXUSMC Posted September 10, 2014 Share Posted September 10, 2014 Just curious on this one as I noticed an issue today when setting up some automation for Outlook. Normally I use this kind of code to see if a registry exists by checking for the default value on a given key (as some programs may not have any other keys and this one is always a given) RegRead(HKCU\XXX\XXXX", "") If @Error Then ;Key Not Found or Cant be Read Else ;Key is found and this registry key is valid EndIf I had this working with the last automation I did as it would find the default key at the parent key for a given program. Today with Outlook however it was giving me "not found" and after some google searching found that its because the default key was "no value" if I changed the value to anything even blank regread would then let me know that the key is valid. So I could use that as part of my If statement to write some new keys to that location. So not sure why it worked before and not now, as a temporary work around I am just searching for the Office14 Parent Key and using RegEnumKey so I can verify that Office14 exist but I was trying to be more specific and make sure a specific program of Office14 was installed. In the future if I am working with a smaller program without multiple keys in a tree and I only have a single master key to search for with possibly random key values, I would like to know if there is a way to search for the default key even if it has a value set for "No Value". Link to comment Share on other sites More sharing options...
jguinch Posted September 10, 2014 Share Posted September 10, 2014 I made my own function for this. Func _RegExistKey($sKeyname) RegEnumVal ($sKeyname, 1) Return (@error <= 0) EndFunc Professor_Bernd 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Kovacic Posted September 10, 2014 Share Posted September 10, 2014 $isDomain = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\History", "MachineDomain") if $isDomain = "MyDomain.com" Then ; Yay! Else ; Crap :( endif C0d3 is P0etry( ͡° ͜ʖ ͡°) Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted September 10, 2014 Author Share Posted September 10, 2014 I made my own function for this. Func _RegExistKey($sKeyname) RegEnumVal ($sKeyname, 1) Return (@error <= 0) EndFunc This is basically what I already did as a work around but the problem is that if your key ONLY has the default key with no value then RegEnumVal will fail thus returning results as if the key did not exist. This can be tested on my system with: $Test = RegEnumVal("HKCU\Software\Microsoft\Windows Media", "1") If @Error Then MsgBox(0, "", "Not Found" & $Test & @Error) Else MsgBox(0, "", "Found" & $Test) EndIf Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted September 10, 2014 Author Share Posted September 10, 2014 $isDomain = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\History", "MachineDomain") if $isDomain = "MyDomain.com" Then ; Yay! Else ; Crap :( endif This is a standard regread, the post is trying to put emphasis on if a value does not exist other than default. If I have other values I could search for them instead but at an administrative level I do not want to search for a value unless I know for a fact it will exist on all machines. Often applications only have a key with values for user name, last server, etc things that are not static for every user thus the only safe value to look for is (Default) because it is created when the program is installed but before any key values are written from users adding there own software settings or configurations. Link to comment Share on other sites More sharing options...
Solution jguinch Posted September 10, 2014 Solution Share Posted September 10, 2014 (edited) my code works. Did you look at it ? It's not the same thing (test of @error) ; yours $Test = RegEnumVal("HKCU\Software\Microsoft\Windows Media", "1") If @Error Then MsgBox(0, "", "Not Found" & $Test & @Error) Else MsgBox(0, "", "Found" & $Test) EndIf ; mine If _RegExistKey("HKCU\Software\Microsoft\Windows Media") Then MsgBox(0, "", "Found" & $Test) Else MsgBox(0, "", "Not Found" & $Test & @Error) EndIf Func _RegExistKey($sKeyname) RegEnumVal ($sKeyname, 1) Return (@error <= 0) EndFunc Edited September 10, 2014 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
guinness Posted September 10, 2014 Share Posted September 10, 2014 https://www.autoitscript.com/wiki/Snippets_%28_Registry_%29#IsRegistryExist UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted September 10, 2014 Author Share Posted September 10, 2014 (edited) my code works. Did you look at it ? It's not the same thing (test of @error) ; yours $Test = RegEnumVal("HKCU\Software\Microsoft\Windows Media", "1") If @Error Then MsgBox(0, "", "Not Found" & $Test & @Error) Else MsgBox(0, "", "Found" & $Test) EndIf ; mine If _RegExistKey("HKCU\Software\Microsoft\Windows Media") Then MsgBox(0, "", "Found" & $Test) Else MsgBox(0, "", "Not Found" & $Test & @Error) EndIf Func _RegExistKey($sKeyname) RegEnumVal ($sKeyname, 1) Return (@error <= 0) EndFunc Ok, that does look like it works. So your just telling RegEnumVal to return a different @Error value? Just trying to wrap my head around how its working, and how it would give a different result if the parent key was not valid. I am assuming that basically the @Error is always -1 if the Main key is valid but it just cant read the value of the sub key. So if the @Error is 0 or higher set @Error as 0 when you return from the function. If the main key was not valid @Error would be higher than 0 (probably 2) and the function would not send a modified @Error value and would pass the greater than 0 value. sound about right? Edited September 10, 2014 by ViciousXUSMC Link to comment Share on other sites More sharing options...
guinness Posted September 10, 2014 Share Posted September 10, 2014 No, they're checking if the @error return value is zero or less, it works though = 0 would have been suffice. See my function instead for an alternative. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
jguinch Posted September 10, 2014 Share Posted September 10, 2014 Guinness, I used Return (@error <= 0) because if @error is 0 or -1, then the registry key exists. Professor_Bernd 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
guinness Posted September 10, 2014 Share Posted September 10, 2014 Ah OK. They just want the key. Sorry. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
jguinch Posted September 10, 2014 Share Posted September 10, 2014 (edited) We can mix the two functions : Func _RegExists($sKeyname, $sValueName = "") Local $iRet RegRead($sKeyName, $sValueName) Return ( $svalueName = "" ? @error <= 0 : @error = 0 ) EndFunc Edited September 11, 2014 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted September 10, 2014 Author Share Posted September 10, 2014 So this works too $Test = RegEnumVal("HKCU\Software\Microsoft\Windows Media", "1") If @Error <= 0 Then MsgBox(0, "", "Found" & $Test & @Error) Else MsgBox(0, "", "Not Found" & $Test) EndIf I tried both > < and <> just did not think to look for @Error meaning yes its working Link to comment Share on other sites More sharing options...
willichan Posted September 10, 2014 Share Posted September 10, 2014 Or, you could have gone here: My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
Elementary Posted November 23, 2020 Share Posted November 23, 2020 Bonjour, un peu tard soit mais jamais trop tard pour bien faire. Voici ma solution : ;======================================================== Func REG_ExistKey($Key) Local $ii=1, $Existe=False, $Value while StringRight($Key,1)=="\" $Key=StringLeft($Key,StringLen($Key)-1) WEnd Local $Prefixe=StringSplit($Key,"\") Local $Suffixe=$Prefixe[$Prefixe[0]] $Prefixe=StringReplace($Key,"\"&$Suffixe,"") While 1 $Value=RegEnumKey($Prefixe,$ii) If @error Then ExitLoop If StringCompare($Value,$Suffixe)==0 Then $Existe=True ExitLoop EndIf $ii+=1 WEnd Return $Existe EndFunc ; --> REG_ExistKey ;======================================================== Func REG_ExistVal($Key,$Val) Local $ii=1, $Existe=False, $Value while StringRight($Key,1)=="\" $Key=StringLeft($Key,StringLen($Key)-1) WEnd While 1 $Value=RegEnumVal($Key,$ii) If @error Then ExitLoop If StringCompare($Value,$Val)==0 Then $Existe=True ExitLoop EndIf $ii+=1 WEnd Return $Existe EndFunc ; --> REG_ExistVal ;======================================================== Salutations. 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