Hex registry key 
Author Message
 Hex registry key

I have a registry key like this:

[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Foo]
"Bar"=hex:01,00,00,00

How do I detect whether this key is set to this exact value?

Here's my current code:

sub Reg_Get
{

    local $VALUE = "";
    if ( NTRegOpenKeyEx ( $MASTERKEY, $KEY, &NULL, &KEY_ALL_ACCESS,
$hkey ) )
    {
        if ( ! NTRegQueryValueEx ( $hkey, $VARIABLE, &NULL, &REG_SZ,
$VALUE ) )
        {
            $VALUE = "";
        }
        NTRegCloseKey( $hkey );
    }
    return $VALUE;

Quote:
}

$FooBar=Reg_Get(&HKEY_LOCAL_MACHINE,
'System\CurrentControlSet\Services\Foo',
'Bar', __FALSE__);
print " Foo/Bar flag is set\n" if $FooBar == "\x01\x00\x00\x00";

It prints the message regardless of what the value is set to. What am
I doing wrong (other than trying to use Perl 5.001 on Win32)? I don't
have a choice of Perl version, I have to work with 5.001 for this.

Phil Hibbs.



Tue, 02 Mar 2004 09:55:38 GMT  
 Hex registry key

Quote:
>Here's my current code:

>sub Reg_Get
>{

>    local $VALUE = "";

See perlfaq7: "What's the difference between dynamic and lexical
(static) scoping? Between local() and my()?"

You almost certainly want to use "my" here.


my $VALUE;

You might also consider using small caps for variable names - most
people I know seem to reserve uppercase for constants.

Quote:
>        if ( ! NTRegQueryValueEx ( $hkey, $VARIABLE, &NULL, &REG_SZ,
>$VALUE ) )
>        {
>            $VALUE = "";

You should set this to undef - there may well be a valid key that
contains an empty string.

Quote:
>print " Foo/Bar flag is set\n" if $FooBar == "\x01\x00\x00\x00";
>It prints the message regardless of what the value is set to. What am
>I doing wrong (other than trying to use Perl 5.001 on Win32)? I don't
>have a choice of Perl version, I have to work with 5.001 for this.

The comparison will always be true since it's 0 == 0 - your RHS is a
character string, not a number. Either use "eq" to compare the
strings, or convert the binary representation to a number, perhaps
using unpack.

And box their ears to get upgraded to 5.6.1. I betcha they don't run
their Windows without current service packs, either.

HTH,
--

split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while



Tue, 02 Mar 2004 10:39:40 GMT  
 Hex registry key

Quote:
> > print " Foo/Bar flag is set\n" if $FooBar == "\x01\x00\x00\x00";

> Either use "eq" to compare the strings,

D'oh, that's the bug!

The actual Reg_Get function isn't mine, I'm trying to re-use existing
code as much as possible both to reduce questions to be asked at code
review, and to reduce the chance of version problems.

Thanks for the help.

Phil Hibbs.



Fri, 05 Mar 2004 10:54:43 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. delete a non empty registry key with tie Registry

2. registry: can create key value but not key.

3. Adding a value to a Registry key???

4. Tie Registry: Delete entire key with subkeys

5. Setting security permissions on registry keys?

6. Win32 Registry.pm incosistent for nonexistent toplevel keys

7. Problems with changing permissions on Winnt Registry Keys.

8. Windows NT Recursive Registry Keys

9. Setting WinNT Registry Key Permissions via script

10. win32 registry keys for Perl

11. How do I rename an NT registry key ?

12. Win32 Registry.pm incosistent for nonexistent toplevel keys

 

 
Powered by phpBB® Forum Software