Reading Binary Registry Keys 
Author Message
 Reading Binary Registry Keys

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?



Sat, 19 Apr 2003 02:22:31 GMT  
 Reading Binary Registry Keys

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

Quote:

> 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?



Sat, 19 Apr 2003 02:40:14 GMT  
 Reading Binary Registry Keys
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
--

Quote:

> 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


> > 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?



Sat, 19 Apr 2003 04:09:34 GMT  
 Reading Binary Registry Keys
Chad... yes I had tried that.
Michael... That works very well. Thanks.

Dave


Quote:
> As of WSH 2.0, you should be getting an array with elements that are

variants of subtype byte.
Quote:

> 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
> --




Quote:
> > 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




- Show quoted text -

Quote:
> > > 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?



Sat, 19 Apr 2003 13:55:50 GMT  
 Reading Binary Registry Keys
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.


Quote:
> As of WSH 2.0, you should be getting an array with elements that are

variants of subtype byte.
Quote:

> 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
> --




- Show quoted text -

Quote:
> > > 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?



Sun, 20 Apr 2003 15:06:50 GMT  
 Reading Binary Registry Keys
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


Quote:
> 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.



> > 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
> > --



> > > > 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?



Sun, 20 Apr 2003 22:17:46 GMT  
 Reading Binary Registry Keys

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

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> 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.



> > 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
> > --



> > > > 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?



Mon, 21 Apr 2003 11:57:32 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Read binary registry key

2. Reading a Binary key from the Registry in JScript

3. Read Registry Keys and Trees / API Call for Registry access

4. REGISTRY How can I read a registry key?

5. RegRead Method with Binary Registry Keys

6. Registry Keys with Binary Values

7. Reading Binary data from the registry

8. Reading binary registry values using regobj.dll

9. Reading Binary Registry Values

10. Reading binary registry entry

11. how to read Binary fields from registry

12. binary REGISTRY KEY VALUES

 

 
Powered by phpBB® Forum Software