Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Pass Hexadecimal through OLE method?

by jpavel (Sexton)
on Mar 26, 2003 at 15:59 UTC ( [id://245968]=perlquestion: print w/replies, xml ) Need Help??

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:
  • HKEY_CLASSES_ROOT &H80000000
  • HKEY_CURRENT_USER &H80000001
  • HKEY_LOCAL_MACHINE &H80000002
  • HKEY_USERS &H80000003
  • HKEY_CURRENT_CONFIG &H80000005
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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://245968]
Approved by robartes
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-24 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found