Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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"; } }

Replies are listed 'Best First'.
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?

      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"

      That appears to be an option ... but read/write could very well be the default.
Re: Read registry error (no tips)
by tye (Sage) 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!
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\

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1001383]
Approved by Corion
[Corion]: Meh. I have a very simple mechanism to scrape+track prices, and even to send me mail if something changes (via cron), but SQLite doesn't support window functions, so my simple SQL to determine a price change won't work :-( Maybe I should store the DB ...
[Corion]: ... in Pg, but that would mean that I'd have to deal with credentials and stuff :)
[Corion]: In fact, the whole thing is just four simple programs, one App::scrape, another being DBIx::RunSQL, and one some glue to convert a JSON object into an SQL INSERT statement (+DBI connect/execute), so it would be an incredibly simple solution...
[Corion]: ... but that simplicity falls down due to SQLite letting me down and me being too lazy to move to a real DB. Maybe DBD::CSV can handle window functions...
[hippo]: Pg has the "trust" mechanism if you don't fancy using credentials for a trivial db.
[Corion]: hippo: Oooh, that sounds quite nice - let me read the documentation on that :)

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2018-02-23 15:05 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (302 votes). Check out past polls.