DigDeep

Registry Key exist or not

11 posts in this topic

#1 ·  Posted

Hi,

I am sure this might have been done earlier but dono where am I going wrong.

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Direct3D\Drivers

I just need to know if the subkey Drivers exists in Direct3D key or not. I don't want any key value or data.

I did tried with RegEnumKey too but I am not getting it correctly.

Local $Drv = HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Direct3D\Drivers

If $Drv exists then
    ; do something
Else
    MsgBox(0, '', 'Drivers Key does not Exist')    
EndIf

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

Its first underneath Direct3D on my few boxes, so this works

msgbox(0, '' , execute('RegEnumKey("HKLM\SOFTWARE\WOW6432Node\Microsoft\Direct3D" , 1) = "Drivers" ? "Yes" : "No"'))

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#3 ·  Posted

I normally use the following function _RegKeyExists in the RegFunc UDF.

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@iamtheky , what if I don't if it would be first or 4th underneath? It shows 3rd line on my Registry.

@Subz thanks you too. Looking into yours too once.

Edited by DigDeep

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Similar to the key's; you can check one by one each element: 

Local $sSubKey = "", $i = 1, $bExists = False
While 1 ;check the folders one by one
    $sSubKey = RegEnumKey("HKLM\SOFTWARE\WOW6432Node\Microsoft\Direct3D", $i) ;or HKLM64
    ;ConsoleWrite($sSubKey & @CRLF)
    If @error Then ExitLoop
    If $sSubKey = "Drivers" Then
        $bExists = True
        ExitLoop
    EndIf
    $i = $i + 1
WEnd
ConsoleWrite($bExists & @CRLF)

 

Edited by taylansan
commented console write

TY.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

maybe misuse @error, because:

Since type cant be messed up in this use case, if the key could be opened the @error value will be 0 or less (either success or value could not be accessed).

#RequireAdmin
$a = RegRead("HKLM\SOFTWARE\WOW6432Node\Microsoft\Direct3D\Drivers" , "test")
msgbox(0, '' , @error  <= 0 ? "YES" : "NO")

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

It looks wierd here...

@Subz

I tried using your Func _RegKeyExist I even tried using the _RegSubkeySearch

It searches few keys, even sub keys correctly but does not read some.

Just to add here, I when I tried adding the @error with _RegKeyExist, it gave me 2 - Target key does not exist

and with RegSubkeySearch, Failure - 0.

But all the below keys were existing...

$key = _RegKeyExists("HKLM\SOFTWARE\WOW6432Node\Microsoft\Direct3D")
MsgBox(0, '', $key) = 1

OR

$key = _RegKeyExists("HKLM\SOFTWARE\WOW6432Node\Microsoft\Direct3D\Drivers")
MsgBox(0, '', $key) = 1

OR

$key = _RegKeyExists("HKLM\SOFTWARE\WOW6432Node\Microsoft\Direct3D\Drivers\Direct3D")
MsgBox(0, '', $key) = 1

OR

$key = _RegKeyExists("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
MsgBox(0, '', $key) = 1

BUT...



$key = _RegKeyExists("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Notifications")
MsgBox(0, '', $key) = 0

And

$key = _RegKeyExists("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate")
MsgBox(0, '', $key) = 0

 

@taylansan I even tried with your example but get the same result as above.

I tried compilation on multiple machines also but all the machines gave me the same above results.

 

Edited by DigDeep

Share this post


Link to post
Share on other sites

#9 ·  Posted

The problem is "HKEY_LOCAL_MACHINE" == "HKLM" i.e. 32bit key, you need to use "HKLM64" to get 64bit keys.

 

1 person likes this

Share this post


Link to post
Share on other sites

#10 ·  Posted

Did you try for this? I mentioned about HKLM64 in the comment. 

$sSubKey = RegEnumKey("HKLM\SOFTWARE\WOW6432Node\Microsoft\Direct3D", $i) ;or HKLM64

 


TY.

Share this post


Link to post
Share on other sites

#11 ·  Posted

Thanks @Subz and all.

I tried with the below and it's working now. :thumbsup:

_RegKeyExists("HKLM64\...

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