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

Hi everyone,

I'm having trouble getting StdRegProv to work with Perl
Can someone help me?

I'm using a Windows XP machine, and I'm running perl 5.8.6. I'm logged on as administrator.

These are my futile attempts:
# !/usr/local/bin/perl -w use strict; use Win32; use Win32::OLE qw(in); my $HKEY_CLASSES_ROOT = 0x80000000; # 2147483648 my $HKEY_CURRENT_USER = 0x80000001; # 2147483649 my $HKEY_LOCAL_MACHINE = 0x80000002; # 2147483650 my $HKEY_USERS = 0x80000003; # 2147483651 my $HKEY_CURRENT_CONFIG = 0x80000005; # 2147483653 my $HKEY_DYN_DATA = 0x80000006; # 2147483654 my $KEY_QUERY_VALUE = 0x0001; my $KEY_SET_VALUE = 0x0002; my $KEY_CREATE_SUB_KEY = 0x0004; my $DELETE = 0x00010000; my $strKeyPath = "SYSTEM\\CurrentControlSet"; my @arrSubKeys = (); my @valueNames = (); my @valueTypes = (); my $wmiService = Win32::OLE->GetObject("winmgmts:\\\\.\\ROOT\\default: +StdRegProv"); my $errorMsg = Win32::OLE->LastError(); print "Error message: $errorMsg\n"; my $tempErrorMsg = Win32::GetLastError(); $errorke = Win32::FormatMessage($tempErrorMsg); print "Error message2 : $tempErrorMsg - > $errorMsg\n"; my @tmpArr = (); $strKeyPath = "Console"; my $strValueName = "HistoryBufferSize"; my $tmpValues; my @tmpTest; my $HasAccessRight; @tmpTest = $wmiService->CheckAccess($HKEY_LOCAL_MACHINE, "HKEY_CURRENT +_USER\\Console", $KEY_QUERY_VALUE, $HasAccessRight); print "Key access rights: $HasAccessRight\n"; # Returns nothing print "Key access rights (2): @tmpTest\n"; # Retruns 2 @tmpTest = $wmiService->GetDWORDValue(2147483649, "HKEY_CURRENT_USER\\ +Console", "NumberOfHistoryBuffers", $tmpValues); $errorMsg = Win32::OLE->LastError(); print "Error message: $errorMsg\n"; $tempErrorMsg = Win32::GetLastError(); $errorMsg = Win32::FormatMessage($tempErrorMsg); print "Error message2 : $tempErrorMsg - > $errorMsg\n"; print "Current History Buffer Size: ".$tmpValues."\n"; # Returns nothi +ng print "Current History Buffer Size (2): @tmpTest\n"; # Returns 2

The $log->info is nothing more than a fancy way to print messages both to the screen and into a logfile.
(has been removed by request of liverpole).

The errors that I print to screen all return value 0 (which means success).
Also, no warnings are displayed.

Thanks in advance. UPDATE:
Code snipset has been updated, by request of liverpole

Replies are listed 'Best First'.
Re: Windows XP: StdRegProv
by liverpole (Monsignor) on Feb 08, 2007 at 18:02 UTC
    Hi jschollen,

    I'm afraid you're going to need to provide more information.

    It looks like you've provided a full program, judging from the fact that you start with the shebang line # !/usr/local/bin/perl -w, followed by your libraries and variables.

    But you haven't declared $log anywhere in your program, much less the associated methods info and infoWarning.

    You've said:  "I'm having trouble getting StdRegProv to work with Perl", but you haven't said exactly how it fails.

    You're also going to get errors with $wmiService unless you declare it (eg. my $wmiService), and the same for $KEY_QUERY_VALUE which is also never declared.

    Can you please fix those problems, and explain how this is failing for you exactly?


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
      The $log is not declared, since it is irrelevant in this case.
      (As I noted under the code snipset: "It's a fancy way of printing data to screen and log file").

      Since it IS a code snipset: it may be that I indeed left out a 'my' declaration. The easiest way to solve this is putting in the 'my' statement or removing the 'use strict'.

      The main problem is stated as comment inside the code snipset:
      1. Win32::OLE->LastError() and Win32::GetLastError() return value 0 (which means success).
      (which means I'm doing everything wright by coding point of view.)

      2. There are no warnings thrown with the '-w' flag (in the original progam.)
      (which also means that I'm doing everything wright by coding point of view.)

      3. When looking at the code:
      @tmpTest = $wmiService->CheckAccess($HKEY_LOCAL_MACHINE, "HKEY_CURRENT +_USER\\Console", $KEY_QUERY_VALUE, $HasAccessRight);
      print "Key access rights: $HasAccessRight\n"; # Returns nothing
      print "Key access rights (2): @tmpTest\n"; # Retruns 2

      The first print ($HasAccessRight) should return the correct value, but it returns an empty string (actual value is 50, checked it with regedit).
      (This is the main problem).
      The second print (@tmpTest) returns value '2'. Normally this value should be 0 (If I read MSDN correctly), while the value 2 MIGHT indicate that I don't have permission (If I read MSDN correctly). The strange thing is, that I'm a full administrator on my Windows XP machine (in which case I should have full access to everyting).
      (Which is probably a lead on what is going wrong, but I'm unable to find the issue.)

      Hence, to repeat my question, Can someone help me getting StdRegProv to work with Perl?

      Thanks in advance.

      (p.s.: I removed all the $log objects and hopefully declared all variables to avoid any other misunderstanding).
        I found the sollution!

        If someone has the same problem, look at the package 'Win32::OLE::Variant'.
        (Thanks to a post by 'Bill Luebkert' on 'Nabble').

        He gave the next example:

        Thanks to all of you who helped me with this issue.