uzzikie has asked for the wisdom of the Perl Monks concerning the following question:

hello everyone
i get this strange error

The system could not find the environment option that was entered here

when i tried to access the registry via a webpage what's even more curious was that my perl scripts previously running on NT4.0 had no problems.... this happened only when i upgraded to Win2K server
here's the snippet of the code straight from the documentation

use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>1 ); $Registry->Delimiter("/"); # Set delimiter to "/". $swKey= $Registry->{"LMachine/Software/"} or die "$^E\n";


and that's where it died. can't get further than this.. of course, the proper permissions have been set to allow the anonymous Internet user (IUSR_MachineName) to read the appropriate keys...

any idea why and more importantly..how to solve?

Edit Masem 2001-07-18 - Added CODE tags

Replies are listed 'Best First'.
Re: TieRegistry problem...environment option ?
by c-era (Curate) on Jul 18, 2001 at 16:12 UTC
    There is a problem with IIS and the Win32 modules. You will always get get that error regardless of what is wrong (thats because the error is in the error reporting code, go figure). Many times you need to set the script to run as system in IIS, even if you have given the IUSR_MachineName user the appropriate rights. Some times you need to run the script as system, and then have the script login as a regular user that has the correct permisions. Make sure you give full pathnames to everything. You also want to check for any mis-spellings.
(tye)Re: TieRegistry problem...environment option ?
by tye (Sage) on Jul 18, 2001 at 19:18 UTC

    From the Win32API::Registry documentation (the module that Win32::TieRegistry is built upon):

    All calls return a true value for success and a false value for failure. After any failure, $^E should automatically be set to indicate the reason. However, current versions of Perl often overwrite $^E too quickly, so you can use regLastError() instead, which is only set by Win32API::Registry routines.
    The error message that Perl most often overwites $^E with is "The system could not find the environment option that was entered".

    Unfortunately, I haven't updated Win32::TieRegistry to document this nor to allow you to do use Win32::TieRegistry ( Delimiter=>"/", 'regLastError' ); so you'll have to add use Win32API::Registry qw( regLastError ); to your script and replace $^E with regLastError(). That will probably shed some light on the problem. If you have an old copy of Win32API::Registry, then you might have to update it.

    I'd guess you are having a permissions problem. Win32::TieRegistry will try to open the key for read and write access and perhaps you only have read access (old versions of the module try to open keys for "all" access). You can try requesting read-only access instead (let us know if you have problems doing that).

    A future version of TieRegistry will instead have a list of "open permissions" that defaults to ( "all", "read+write", "read-only" ) and will try those modes in sequence and only fail to open if all three attempts fail.

            - tye (but my friends call me "Tye")
      hi tye

      thanks for ur help.....
      regLastError() did indeed report a more meaningful error being

      Access Denied

      I had wanted the script to read one of the sub keys in LMachine/Software but proper permissions (full control)were set for the sub keys ONLY
      thus when the script tried to read LMachine/Software it said access denied.

      Subsequently I made the script read the subkey directly
      <code>$swKey= $Registry->{"LMachine/Software/Subkey1/Subkey2/"}<code>
      and this solved the problem..

      thanks again for all ur help guys...