Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Read registry error

by anaconda_wly (Scribe)
on Oct 29, 2012 at 15:30 UTC ( #1001383=perlquestion: print w/ replies, xml ) Need Help??
anaconda_wly has asked for the wisdom of the Perl Monks concerning the following question:

It's nearly copied from CPAN help, but when run only show "can't find..."message. I'm using Windows7. Anyone help? Thanks!

use Win32::TieRegistry( Delimiter => '/' ); sub isExist{ my $tips= $Registry->{"HKEY_LOCAL_MACHINE/Software/Microsoft/"} or die "Can't find the Windows tips: $^E\n"; foreach( keys %$tips ) { print "$_: ", $tips->{$_}, "\n"; } }

Comment on Read registry error
Download Code
Re: Read registry error
by Anonymous Monk on Oct 29, 2012 at 16:22 UTC
    what is $^E in the error message?
      The error message was"The system could not find the environment option that was entered"
        That is bizzare. Try  C:\> reg query HKEY_LOCAL_MACHINE\Software\Microsoft\
Re: Read registry error
by brap (Pilgrim) on Oct 29, 2012 at 17:30 UTC

    Hi anaconda_wly,

    Just for grins, I tried this on a pretty locked-down Windows 7 machine. The error message I received was Can't find the Windows tips: The system could not find the environment option that was entered. I have no idea what that means.

    Knowing that the PC I'm using is locked down, I tried changing the root key to HKEY_CURRENT_USER. With that change, your code worked as posted.

    I wonder if Win32::TieRegistry is opening the registry key for read/write access?

      That appears to be an option ... but read/write could very well be the default.

      Brap, I'm trying. While I tried a use

      Win32::TieRegistry( Access=>KEY_READ, Delimiter => '/' );

      but get an error "Bareword "KEY_READ" not allowed while "strict subs" in use"

Re: Read registry error (no tips)
by tye (Cardinal) on Oct 30, 2012 at 02:20 UTC

    Windows 7 doesn't come with Tips. Below I picked a different Registry key that I find often fills up with simple text data and also only asked for 'read' access:

    use Win32::TieRegistry( Delimiter => '/' ); sub isExist{ my $tips= $Registry->Open( "HKEY_LOCAL_MACHINE/Software/Microsoft/Windows/CurrentVersion/ +Run/", { Access => 'KEY_READ' }, ) or die "Can't find the 'Run' key: $^E\n"; foreach( keys %$tips ) { print "$_: ", $tips->{$_}, "\n"; } } isExist();

    It works for me on Windows 7. But it wouldn't work if you don't even have 'read' access to that part of the Registry (seems unlikely). And it will report nothing if you don't have any "Run" entries (I've never been so lucky).

    - tye        

      Your way is OK for me. Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1001383]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-12-25 16:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls