
Reading REG_BINARY Keys with RegObj.dll
Treat it as a string of bytes instead of an array.
Here's a .wsf example of how to get it into the same form that the
WshShell.RegRead method returns (a variant array with each element being a
variant of subtype byte).
For this example I used regedit to manually create
"HKEY_CURRENT_USER\MyKey\binValue" with a value of "11 22 33 44".
<job>
<object id="reg" progid="regobj.registry" reference="yes" />
<script language="VBScript">
set regKey = reg.RegKeyFromString("\HKEY_CURRENT_USER\MyKey")
theBinaryValue = regKey.Values("binValue").Value
redim byteArray(lenb(theBinaryValue)-1)
for n = 1 to lenb(theBinaryValue)
byteArray(n-1) = cbyte(ascb(midb(theBinaryValue,n,1)))
next
msgbox hex(byteArray(0))
</script>
</job>
Of course, this is a one way conversion... You can't create a true byte
array (TypeName --> Byte()) with just script.
But there is a free MS component that is very useful for dealing with binary
data in script. It was supposed to be included in the ADSI SDK (but didn't
make it).
Q250344 - SAMPLE: ARRAYCONVERT.EXE Variant Conversion Functions
http://support.microsoft.com/support/kb/articles/Q250/3/44.ASP
--
Michael Harris
Microsoft.MVP.Scripting
--
Please do not email questions - post them to the newsgroup instead.
--
Quote:
> I am trying to read a key of data type REG_BINARY, but I am having
> problems. The value is 06 00 09 00 00 00. Basically, it appears to be
> an array:
> IsArray(objRegKey.Values(ValueName).Value) returns "True"
> LBound(objRegKey.Values(ValueName).Value) returns "0"
> UBound(objRegKey.Values(ValueName).Value) returns "5"
> VarType(objRegKey.Values(ValueName).Value) returns "8209"
> 8209 = 8192 (array) + 17 (byte) - an array of bytes
> But any access to any elements of the array fail with the error "Type
> mismatch" (code: 800A000D). How do I access REG_BINARY registry types,
> and more specifically, how do I handle that data?
> --
> Rick Kasten, MCSE SysAdmin Consultant
> Collective Technologies http://www.colltech.com
> Sent via Deja.com
> http://www.deja.com/