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

Help me, O wise ones...

I've got a Perl script--converted from one in VBasic, that reads the registry and places its result into a variable passed in as an argument. The function's return is just 0 for success, anything else for failure. Is there *any* way to get my perlish paws on the result? Here's the code:

#!perl # The following example reads and displays the value in the DWORD regi +stry value # HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CrashControl\Aut +oReboot. use Win32::OLE; use constant HKEY_LOCAL_MACHINE => 0x80000002; my $dwValue = 42; $strComputer = '.'; $oReg = Win32::OLE->GetObject('winmgmts:{impersonationLevel=impersonat +e}!\\\\' . $strComputer . '\\root\\default:StdRegProv'); $strKeyPath = 'SYSTEM\\CurrentControlSet\\Control\\CrashControl'; $strValueName = 'AutoReboot'; $oReg->GetDWORDValue(HKEY_LOCAL_MACHINE, $strKeyPath, $strValueName, $ +dwValue); print 'AutoReboot' . ' == ' . $dwValue, "\n";


The output, as might be expected, is:

"AutoReboot == 42"

The vbs script, of course, works just fine, setting $dwValue to 1 (the current value on my PC). Thanks for any insight--especially one that shows the way...

Dismas

Replies are listed 'Best First'.
Re: Value Sought from Subroutine Argument?
by friedo (Prior) on Mar 02, 2005 at 15:23 UTC
    You probably need to pass $dwValue as a reference. Try

    my $dwValue = 42; $oReg->GetDWORDValue(HKEY_LOCAL_MACHINE, $strKeyPath, $strValueName, \$dwValue);
      Dear Friedo,

      Nope. No joy. Thanks for the suggestion, I do appreciate you taking the time to answer, but it didn't help.

      Dismas
Re: Value Sought from Subroutine Argument?
by dragonchild (Archbishop) on Mar 02, 2005 at 15:43 UTC
    Have you tried assigning the result of GetDWORDValue() to $dwValue? I don't use the Win32 namespace, but that would be something I'd try.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      Dear Dragonchild,

      If by "result" you mean the value returned, that won't do. The sub returns a 0 for success and an error code for failure.

      Thanks JTS,

      Dismas
Re: Value Sought from Subroutine Argument?
by PodMaster (Abbot) on Mar 03, 2005 at 07:54 UTC
    No need to play with OLE when you can use Win32::Registry
    use strict; use warnings; use Win32::Registry; # The following example reads and displays the value in the DWORD regi +stry value # HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CrashControl\Aut +oReboot. my $CrashControl; $::HKEY_LOCAL_MACHINE->Open( q~SYSTEM\CurrentControlSet\Control\CrashControl~, $CrashControl ) or die "Can't open CrashControl: $^E"; my ($type, $value); $CrashControl->QueryValueEx("AutoReboot", $type, $value) or die "No Au +toReboot: $^E"; print "Here's AutoReboot: $value\n";

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Value Sought from Subroutine Argument?
by ikegami (Patriarch) on Mar 02, 2005 at 18:03 UTC

    This is odd. I wonder how Win32::OLE determines the arguments of the functions. I noticed that MSDN documents the argument as being uint32, not uint32& or uint32*. I wonder if that is related.

    I tried passing a pointer using unpack('I', pack('P', $dwValue)), but it didn't help.