Jump to content

RegRead and (default) value


Recommended Posts

I've been beating my head against this problem for a while now and I just can't seem to get it.

I'm trying to check for the existence of certain registry keys by checking for the presence of the (Default) value. The helpfile states:

"To access the (Default) value use "" (a blank string) for the valuename."

The problem is that @error seems to be returning -1 (unable to open requested value).

The code is simple enough..

; $linedata[4] is set from a previous operation to a value such as below:
$linedata[4] = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\KB828028"

$regcheck = RegRead ( $linedata[4], "" )
$error = @error
if $error <> 0 then $gonogo = 1

I thought about setting up condition statements using the value of $regcheck and then I realized that it's going to return the same null value under all conditions so it can't be used - all I have to go on is @error. Testing with a known, existing reg key does return a string for $regcheck and @error = 0 -- it just doesn't seem to work with the (Default) value.

Link to comment
Share on other sites

I've been beating my head against this problem for a while now and I just can't seem to get it.

I'm trying to check for the existence of certain registry keys by checking for the presence of the (Default) value.  The helpfile states:

"To access the (Default) value use "" (a blank string) for the valuename."

The problem is that @error seems to be returning -1 (unable to open requested value).

The code is simple enough..

; $linedata[4] is set from a previous operation to a value such as below:
$linedata[4] = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\KB828028"

$regcheck = RegRead ( $linedata[4], "" )
$error = @error
if $error <> 0 then $gonogo = 1

I thought about setting up condition statements using the value of $regcheck and then I realized that it's going to return the same null value under all conditions so it can't be used - all I have to go on is @error.  Testing with a known, existing reg key does return a string for $regcheck and @error = 0 -- it just doesn't seem to work with the (Default) value.

<{POST_SNAPBACK}>

If you look at the code you are using $linedata[4] as an array. RegRead dont return an array it return the value string try your code by removing [4]

; $linedata is set from a previous operation to a value such as below:

$linedata = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\KB828028"

$regcheck = RegRead ( $linedata, "" )

$error = @error

if $error <> 0 then $gonogo = 1

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

This is normal cause it can't return a value cause there is no value _set_!

You can reproduce it by just doubleclicking the 'Default'-value and then just

'enter' it.

You will see that the result is different.

Then just 'delete' this entry and you will see that it will not deleted but just going to value "value not set" (don't know how it is shown in english).

The 'Default'-entry is always there.

But often it is not set!

Regards

Holger

Edited by Holger
Link to comment
Share on other sites

This is normal cause it can't return a value cause there is no value _set_!

You can reproduce it by just doubleclicking the 'Default'-value and then just

'enter' it.

You will see that the result is different.

Then just 'delete' this entry and you will see that it will not deleted but just going to value "value not set" (don't know how it is shown in english).

The 'Default'-entry is always there.

But often it is not set!

I know - that's the problem.

Is there a way to check for the presence of a registry key for which there is no set default value? There are tons of such programmatically created registry keys.

RegEnumKey and RegEnumVal also won't work for this type of situation.

Link to comment
Share on other sites

If you look at the code you are using $linedata[4] as an array.  RegRead dont return an array it return the value string try your code by removing [4]

; $linedata is set from a previous operation to a value such as below:

$linedata = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\KB828028"

$regcheck = RegRead ( $linedata, "" )

$error = @error

if $error <> 0 then $gonogo = 1

<{POST_SNAPBACK}>

Danny, thanks for your reply.

Just an FYI - the linedata array is already populated from a previous operation (a stringsplit). I just included $linedata[4] to show what type of data was being referenced.

Link to comment
Share on other sites

If you use RegRead() and the key is not there then the @error macro is set to "1"!

So then you know when the result is "0" or "-1" the key exists :whistle:

<{POST_SNAPBACK}>

Well beat me with a stick and call me a dummy.

Checking for the inverse condition AND paying closer attention to the docs.. Who'da thunk* it?

*thunk - the sound made when I'm hit with aforementioned stick.

Thanks Holger!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...