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

Again, for all OLE gurus... This should be an easy one for somebody. Using Win32::OLE, once I connect to root\default, I get the StdRegProv object. This object has an EnumKey method, which I am trying to call. The very first input value of this method is hexadecimal... and I can't quite format my variable correctly to get it to accept it. Here's the stuff:
@host = ($server,"root/default",$user,$password); $localWMI = Win32::OLE->new('WbemScripting.SWbemLocator') or die "Cann +ot access WMI on local machine: ", Win32::OLE->LastError; $WMI = $localWMI->ConnectServer(@host) or die "Cannot access WMI on re +mote machine: ", Win32::OLE->LastError; $registry = $WMI->Get("StdRegProv") or print "Failed to get registry." +; my $err = Win32::OLE->LastError(); if ($err == 0) {print "Successful!\n";} else {print $err;} $base = "Software\\"; $registry->EnumKey('H80000002', $base, @result); my $err = Win32::OLE->LastError(); if ($err == 0) {print "Successful!\n";} else {print $err;}
From all the <gag> VBS </gag> code I can gather from other sources, the constants that the first field accepts are: In CScript, the constant is of course set simply as
Const HKEY_LOCAL_MACHINE = &H80000002

(ref: Microsoft's site...)

No matter how I try to set the variable, I always get: OLE exception from "SWbemObject": Type mismatch Win32::OLE(0.1502) error 0x80041005 in METHOD/PROPERTYGET "EnumKey"

Anybody know the correct format to pass a hexadecimal value to an OLE method call???

Replies are listed 'Best First'.
Re: Pass Hexadecimal through OLE method?
by zakb (Pilgrim) on Mar 26, 2003 at 16:07 UTC

    Bit of a shot in the dark, but if I'm not mistaken, the Const HKEY_LOCAL_MACHINE = &H80000002 will simply convert the hex value to a decimal one, storing it most likely in a long int.

    Have you tried:

    $registry->EnumKey(hex('80000002'), $base, @result);
      Works like a charm. And boy, do I feel like an idiot now. Of course it changes it to an int! And I'm sure passing 2147483650 would have the same result. Thanks!