Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reading Binary Registry Keys

1,057 views
Skip to first unread message

Dave

unread,
Oct 30, 2000, 1:22:31 PM10/30/00
to

Hi,
I'm trying to read in the value from a registry key that contains a binary
string similar to:
54 68 69 73 20 69 73 20 61 20 74 65 73 74 2E

I've tried using RegRead which doesn't error but I can't diplay or store the
values. I want to be able to modify some of the values in the string based
on position and then write the modified values back to the registry. Do I
need to somehow read the values into an array?

Chad Myers

unread,
Oct 30, 2000, 1:40:14 PM10/30/00
to

WshShell.RegRead supports the registry type REG_BINARY, so it should
work.

Perhaps it returns a byte array or something instead of a string?

Have you tried:

Dim vValue
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
vValue = WshShell.RegRead("YOUR_KEY")
WScript.Echo vValue(0)

Does this work?

-Chad

"Dave" <ma...@ihug.co.nz> wrote in message news:O3coV5pQAHA.247@cppssbbsa03...

Michael Harris

unread,
Oct 30, 2000, 3:09:34 PM10/30/00
to
As of WSH 2.0, you should be getting an array with elements that are variants of subtype byte.

sKey = "HKEY_CURRENT_USER\mykey\binKey\"
set shell = createobject("wscript.shell")
val = shell.regread(sKey)
msgbox typename(val)
msgbox typename(val(0))
msgbox val(0)

--
Michael Harris
Microsoft.MVP.Scripting
--


"Chad Myers" <cmy...@NOSPAM.austin.rr.com> wrote in message news:OpDoMDqQAHA.246@cppssbbsa04...

Dave

unread,
Oct 31, 2000, 12:55:50 AM10/31/00
to
Chad... yes I had tried that.
Michael... That works very well. Thanks.

Dave

"Michael Harris" <Please....@To.NewsGroup> wrote in message
news:ulN$i1qQA...@cppssbbsa02.microsoft.com...

Dave

unread,
Nov 1, 2000, 2:06:50 AM11/1/00
to
It seems that I still have a problem...
I can read the values OK, and change them but I can't write them back to the
registry.
Set WshShell=CreateObject("Wscript.Shell")
strKey = "HKCU\MyKey\Test"
answer = WshShell.Regread(strKey)
answer(5)=76
WshShell.RegWrite "HKCU\MyKey\Test\", answer

The last line gives me a type mismatch. If I try
WshShell.RegWrite "HKCU\MyKey\Test\", answer(5)
I don't get any errors but the registry value doesn't change.
I've tried looking in the WSH and VBscript documentation downloaded from
microsoft and looked in other WSH reference sources but I can't find out how
to do this.


"Michael Harris" <Please....@To.NewsGroup> wrote in message
news:ulN$i1qQA...@cppssbbsa02.microsoft.com...

> As of WSH 2.0, you should be getting an array with elements that are
variants of subtype byte.
>
> sKey = "HKEY_CURRENT_USER\mykey\binKey\"
> set shell = createobject("wscript.shell")
> val = shell.regread(sKey)
> msgbox typename(val)
> msgbox typename(val(0))
> msgbox val(0)
>
> --
> Michael Harris
> Microsoft.MVP.Scripting
> --
>
>
> >

Al Dunbar

unread,
Nov 1, 2000, 9:17:46 AM11/1/00
to
To write to the registry you need to include the third RegWrite argument,
strType. In this case you should use REG_BINARY, and keep in mind that it
does not accept an array such as returned by RegRead, but rather a binary
(not string) value Dino Esposito's book "Windows Script Host Programmer's
reference suggests the for-next loop below for converting the array returned
by RegRead to the appropriate binary representation. I can't quite find his
info on RegWrite, but perhaps you need to prefix the binary string with the
hex constant prefix as in my call to RegWrite

str = ""
for each char in answer
datum = right( "00" & hex(char), 2 )
str = datum & str
next

WshShell.RegWrite "HKCU\MyKey\Test\", "&h" & str, REG_BINARY

"Dave" <ma...@NOSPAM.ihug.co.nz> wrote in message
news:8tofct$pal$1...@lust.ihug.co.nz...

Michael Harris

unread,
Nov 1, 2000, 10:57:32 PM11/1/00
to

You can't RegWrite a binary key/value bigger than a Long (as documented) using the WshShell object.

--
Michael Harris
Microsoft.MVP.Scripting
--

"Dave" <ma...@NOSPAM.ihug.co.nz> wrote in message news:8tofct$pal$1...@lust.ihug.co.nz...

0 new messages