Problem reading a registry key..

M

MSG

I am having trouble reading a particular Registry key on WinXP.

-----------------------------
#!perl

use strict;
use warnings;
use Win32::TieRegistry ( Delimiter=>'/' );

my $basekey = "LMachine/System/CurrentControlSet/Enum/";

my $reg = $Registry -> { $basekey }
or die "Failed at $basekey:\n -- $^E\n";

print join "\n", keys( %{$reg} );
------------------------------

It will error out and say:
"The system could not find the environment option that was entered"

That script can read all the sibling and parent keys without any
problems, just nothing under the Enum key.

I'd appreciate that someone can shine some light here!
 
D

Dave

MSG said:
I am having trouble reading a particular Registry key on WinXP.

-----------------------------
#!perl

use strict;
use warnings;
use Win32::TieRegistry ( Delimiter=>'/' );

my $basekey = "LMachine/System/CurrentControlSet/Enum/";

my $reg = $Registry -> { $basekey }
or die "Failed at $basekey:\n -- $^E\n";

print join "\n", keys( %{$reg} );
------------------------------

It will error out and say:
"The system could not find the environment option that was entered"

That script can read all the sibling and parent keys without any
problems, just nothing under the Enum key.

I'd appreciate that someone can shine some light here!

Could you post the code that works too? (i.e. the code that reads parent and
sibling keys).
 
M

MSG

Dave said:
Could you post the code that works too? (i.e. the code that reads parent and
sibling keys).
Just change $basekey to
$basekey = "LMachine/System/CurrentControlSet/"; # parent
or
$basekey = "LMachine/System/CurrentControlSet/control"; #sibling
and it will display a ist of sub keys. But just not on Enum.
 
D

Dave

MSG said:
Just change $basekey to
$basekey = "LMachine/System/CurrentControlSet/"; # parent
or
$basekey = "LMachine/System/CurrentControlSet/control"; #sibling
and it will display a ist of sub keys. But just not on Enum.

Thanks. I can reprodice you problem as long as I run it as an Administrator.
Under an limited user account I get the same error as you get on Enum on all
keys (even though I can view them as an limited user running regedit).

Try this (it works):

use strict;
use warnings;
use Win32::TieRegistry ( Delimiter=>'/' );

my $key = $Registry->Open("LMachine/System/CurrentControlSet/Enum/",
{Access=>1}) || die "$^E\n";

print join "\n", keys( %{$key} );


See:
http://www.mail-archive.com/[email protected]/msg34839.html

and from the TieRegistry documentation:
The "Access" option specifies what level of access to the Registry key you
wish to have once it has been opened. If this option is not specified, the
new key [$subKey] is opened with the same access level used when the old key
[$key] was opened. The virtual root of the Registry pretends it was opened
with access KEY_READ()|KEY_WRITE() so this is the default access when
opening keys directory via $Registry. If you don't plan on modifying a key,
you should open it with KEY_READ access as you may not have KEY_WRITE access
to it or some of its subkeys.

If the "Access" option value is a string that starts with "KEY_", then it
should match &one; of the predefined access levels [probably "KEY_READ",
"KEY_WRITE", or "KEY_ALL_ACCESS"] exported by the Win32API::Registry module.
Otherwise, a numeric value is expected. For maximum flexibility, include use
Win32::TieRegistry qw:)KEY_);, for example, near the top of your script so
you can specify more complicated access levels such as
KEY_READ()|KEY_WRITE().
 
M

MSG

Dave said:
use Win32::TieRegistry ( Delimiter=>'/' );

my $key = $Registry->Open("LMachine/System/CurrentControlSet/Enum/",
{Access=>1}) || die "$^E\n";
If the "Access" option value is a string that starts with "KEY_", then it
should match &one; of the predefined access levels [probably "KEY_READ",
"KEY_WRITE", or "KEY_ALL_ACCESS"] exported by the Win32API::Registry module.
Otherwise, a numeric value is expected. For maximum flexibility, include use
Win32::TieRegistry qw:)KEY_);, for example, near the top of your script so
you can specify more complicated access levels such as
KEY_READ()|KEY_WRITE().

Thank you Dave for the tip. It works out great!
An update:
my $key = $Registry->Open("LMachine/System/CurrentControlSet/Enum/",
{Access=>1}) || die "$^E\n";
That only gets the Registry values, not sub keys.
To read both Registry sub keys and values, do as what the document
says:
use Win32::TieRegistry qw:)KEY_);
my $key = $Registry->Open("LMachine/System/CurrentControlSet/Enum/",
{Access=>'KEY_READ'}) || die "$^E\n";

But I am still wondering why the Enum key is so different from other
keys. Its permission setting in Windows is everyone readable.

Anyway there is some more reading to do on Tie::Registry.
Thanks again, Dave!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top