Sign in to follow this  
Followers 0
BigfootMoeron

Determine if a Registry KEY exists (not a value)

14 posts in this topic

None of the 3 Reg read commands (regenumkey, regenumval, regread) in the help file seems to be able to assist me in determining if a SPECIFIC reg key exists (and the RegSearch function seems overkill).

I am scripting an install of Acrobat Reader's latest patched version.

I just need to know if the specific KEY:

HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\Acrobat Reader\8.0\Installer\Updates\812

exists. If so, I will exit, if not I will call the install and get it on the system.

Will I have to return all keys under "Updates" using a RegEnumKey loop and search for 812, or is there a more direct way?

Sorry for the noob Q!!!

Share this post


Link to post
Share on other sites



Hello!

I think you can use RegRead() . It will return "" if the key doesn't exist.


I ran. I ran until my muscles burned and my veins pumped battery acid. Then I ran some more.

Share this post


Link to post
Share on other sites

Yes, but RegRead seems to return "" if the key DOES exist too!

Any other ideas out there?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

RegRead

--------------------------------------------------------------------------------

Reads a value from the registry.

RegRead ( "keyname", "valuename" )

Parameters

keyname The registry key to read.

valuename The value to read.

Return Value

Success: Returns the requested registry value. @EXTENDED is set to the type of the value $REG_... . These types are defined in the "Constants.au3" include file.

Failure: Returns "" and sets the @error flag:

1 if unable to open requested key

2 if unable to open requested main key

3 if unable to remote connect to the registry

-1 if unable to open requested value

-2 if value type not supported

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

RegEnumKey ( "keyname", 1 )
If @Error Then
   Do whatever
Else
   Do something Else
EndIf

From the help file entry for RegEnumKey

Success: Returns the requested subkey name..

Failure: Returns an error message string and sets the @error flag:

1 if unable to open requested key

2 if unable to open requested main key

3 if unable to remote connect to the registry

-1 if unable to retrieve requested subkey (key instance out of range)


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

I understand, but as I said in the original request, I don't want to have to enumerate the keys, I want to look for a specific key.

I want to know if the key named "812" exists, not have to parse up to 20 keys in a FOR loop and check to see any of the iterations return "812".

Share this post


Link to post
Share on other sites

I understand, but as I said in the original request, I don't want to have to enumerate the keys, I want to look for a specific key.

I want to know if the key named "812" exists, not have to parse up to 20 keys in a FOR loop and check to see any of the iterations return "812".

And I'm say that all you have to do is Enum the first instance to get a return value. Read RegEnumKey() in the help file. You are getting what you were trying to accomplish with RegRead(), which won't do it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Thank you.

There could be up to 20 keys with the one labeled "812" I am looking for. There could be 801, 802, 803, ... 811, 812, ... 819, 820

So enumerating just the first key does not guarantee that 812 is or is not one of those keys.

I guess I just need to run a for loop and compare values.

Wonder why there is no direct way to look for a specific key.

Thanks anyway.

Share this post


Link to post
Share on other sites

Thank you.

There could be up to 20 keys with the one labeled "812" I am looking for. There could be 801, 802, 803, ... 811, 812, ... 819, 820

So enumerating just the first key does not guarantee that 812 is or is not one of those keys.

I guess I just need to run a for loop and compare values.

Wonder why there is no direct way to look for a specific key.

Thanks anyway.

Post the actual key (full path) that you are looking for and I will give you an example. You shouldn't need a loop.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I don't understand what's so hard to grasp:

RegRead('HKLM\Software\Blah','')

If @error = 1 Then Msgbox(0, 'Error', 'Key "HKLM\Software\Blah" not found.')

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

this is not my script... thanks to whoever made this...

#include <GUIConstants.au3>

GUICreate("Registry Search",500,80)
$info_text = GUICtrlCreateLabel("",10,10,480,60)
GUISetState()

Global $found = ""

SearchReg("HKLM","Acrobat Reader\8.0\Installer\Updates\812")
;SearchReg("HKLM","Installer\Updates\812")
GUIDelete()

Msgbox(0,"",$found)

Exit


;*****************************************************
; Recursive search-function
;*****************************************************

Func SearchReg($startkey,$searchval)
    Local $val,$i,$key,$z
    
    $i = 1
    While 1
        $key = RegEnumKey($startkey,$i)
        If @error <> 0 Then ExitLoop
        GUICtrlSetData($info_text,$startkey & "\" & $key)
        $z = 1
        While 1
            $val = RegEnumVal($startkey & "\" & $key,$z)
            If @error <> 0 Then ExitLoop
            If StringInStr($val,$searchval) Then $found = $found & "ValueName, " & $startkey & "\" & $key & ", " & $val & @LF
            $readval = RegRead($startkey & "\" & $key,$val)
            If $readval <> "" And StringInStr($readval,$searchval) Then $found = $found & "Value, " & $startkey & "\" & $key & ", " & $val & ", " & $readval & @LF
            $z = $z + 1
        WEnd
        SearchReg($startkey & "\" & $key,$searchval)
        $i = $i + 1
    WEnd
;Sleep(1); just 1 idle milli second -> not used at the moment
EndFunc
Edited by mikiutama

Share this post


Link to post
Share on other sites

I don't understand what's so hard to grasp:

RegRead('HKLM\Software\Blah','')

If @error = 1 Then Msgbox(0, 'Error', 'Key "HKLM\Software\Blah" not found.')

Absolutly correct. I forgot all about the @Error return for RegRead(). The OP is correct that if the key doesn't exist then RegRead will return "", but it also sets @Error.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

I don't understand what's so hard to grasp:

RegRead('HKLM\Software\Blah','')

If @error = 1 Then Msgbox(0, 'Error', 'Key "HKLM\Software\Blah" not found.')

What's so hard to grasp? How about I am an idiot. :-)

Sorry, I understand now.

I never tried the RegRead without a "valuename" ... read the help file and though it never specified it, I ASSUMED (yes, I know what happens when I assume) that the valuename was required.

What you did above was perfect.

Thank you so much and sorry again for being a bonehead!!

Share this post


Link to post
Share on other sites

PS - I see now in the help file that I can use "" for the DEFAULT value -- never associated DEFAULT with just the name of the key.

I feel like a moron.....

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0