in reply to Re: Where's the result??? (problem with Win32::OLE)
in thread Where's the result??? (problem with Win32::OLE)

Anyone want to take this on? I'm not that fluent with OLE::Variants, but in order to capture registry keys, you need to pass an array. For instance, to get all the subkeys under "HKEY_Users"...
$base = ''; my @keys = Variant(VT_ARRAY|VT_UI1, ''); $result = $registry->EnumKey(2147483651, $base, @keys); print "$base\nResult: $result\n"; foreach $key (@keys) { print "Key:$key\n"; }
I _thought_ this would propogate with the keys. No such luck. I also tried initializing the blank array to a SID (since that is the length it is going to match) but again, no luck.

Replies are listed 'Best First'.
Re: Re: Re: Where's the result??? (problem with Win32::OLE)
by jand (Friar) on Mar 26, 2003 at 23:04 UTC
    Try this:
    my $keys = Variant(VT_BYREF|VT_VARIANT); my $result = $registry->EnumKey(2147483651, $base, $keys); my @dim = $keys->Dim; for ($dim[0][0] .. $dim[0][1]) { my $key = $keys->Get($_); # ... }
      jand, is there I way I can up your guru score? Again, I had to pass:
      my $keys = Variant(VT_BYREF|VT_VARIANT, 0);
      But that did it! I'm ecstatic to have a solution, but I don't fully understand it... what was wrong with using VT_ARRAY? I don't quite get the Dim function, nor why the array is mulitdimensional (or appears to be... we're going from [0][0] .. [0][1]?). I've probably harassed jand enough... can anyone pose an explanation?
        You are probably using an older version of Win32::OLE if you have to provide the second argument to Variant() in this case.

        The Dim() method returns a list of array bounds. Each element of the list is an array ref to a 2 element array containing the lower and the upper bound of that dimension. Although SAFEARRAYs typically have a lower bound of 0, this is not always true.

        So by iterating from $dim[0][0] .. $dim[0][1] we go from the lower to the upper bound of the first dimension of the underlying SAFEARRAY. Ideally, you should check that the returned VARIANT is actually an array, and that the @dim array only contains a single element.

Re: Re: Re: Where's the result??? (problem with Win32::OLE)
by jand (Friar) on Mar 26, 2003 at 21:27 UTC
    I'm in a hurry right now, but one thing I can spot immediately: @keys should be $keys, as VARIANTs are always scalars. In this case you have a reference to a SAFEARRAY, not a Perl level array.

    Oh, and another thing: Win32::OLE may be treating one dimensional arrays of VT_UI1 specially, so I'm not sure if this might complicate things some more.