RegWrite large Binary values to the registry 
Author Message
 RegWrite large Binary values to the registry

I have posted the following questions in a prior thread and the information
Michael Harris gave works great on writing bytes to the registry. However,
it works for 7 bytes or less.

My question now is, I have the need to write Binary Data to the registry,
and many of these Binary Values are 16 bytes or longer. I have no problem
reading the values, they read into an array of variants as described by
Michael. How can I write these long Binary values back to the registry? CLng
(x) only works on Hex numbers 7 bytes long or less. Michael, if you can
help, your reply is greatly appreciated. Attached is our prior conversation.

TIA

Kenny

<snip>

To expand a bit...

Suppose you wanted to set the value back to "95 00 00 00".  The way you do
that is not entirely
intuitive since to you need to pass a long value.

newVal = CLng(&h00000095)

set shell = createobject("wscript.shell")
sKey = "HKEY_CURRENT_USER\Software\"_
     & "Microsoft\Windows\CurrentVersion\"_
     & "Policies\Explorer\"
sVal = "NoDriveTypeAutoRun"

shell.RegWrite sKey & sVal, newVal, "REG_BINARY"

In general, to get a REG_BINARY value of "aa bb cc dd" (as displayed by
RegEdit - the embedded
spaces are only for display) you need to define the hex string passed to
CLng() with the bytes
reversed.

newVal = CLng(&hddccbbaa)

When written as a REG_BINARY value, this will appear in RegEdit as "aa bb cc
dd".

--
Michael Harris
MVP Scripting

"It always helps to read the documentation first..."


You can only RegWrite a REG_BINARY value from a Long...

set shell = createobject("wscript.shell")
sKey = "HKEY_CURRENT_USER\Software\"_
     & "Microsoft\Windows\CurrentVersion\"_
     & "Policies\Explorer\"
sVal = "NoDriveTypeAutoRun"

shell.RegWrite sKey & sVal, CLng(0), "REG_BINARY"

--
Michael Harris
Microsoft MVP - Scripting

"It always helps to read the documentation first..."


Quote:
> Michael,

> The code example you gave works like a champ for reading, I see how it
reads
> in to an Array of bytes, and how to format a display of the bytes.

> Now the final part of the puzzle.....

> How to assign a new 4 byte value to that key.

> For example, instead of 95 00 00 00
> I want to write 00 00 00 00 (And it has to show up in the registry as
> numbers, not a string)

> I tried writing arBytes back to the same key, but again, type mismatch.

> Thanks for all your help!

> kenny



> > This works for WSH 2.0 (WScript.Version -> 5.1)...

> > set shell = createobject("wscript.shell")
> > sKey = "HKEY_CURRENT_USER\Software\"_
> >      & "Microsoft\Windows\CurrentVersion\"_
> >      & "Policies\Explorer\"
> > sVal = "NoDriveTypeAutoRun"

> > arBytes = shell.RegRead(sKey & sVal)

> > for each byt in arBytes
> >   s = s & right("0" & hex(byt),2) & " "
> > next

> > msgbox s

> > --
> > Michael Harris
> > Microsoft MVP - Scripting

> > "It always helps to read the documentation..."



> > > Thanks for the explanation Michael,

> > > I guess what I need to know is how to code a RegRead that will get
these
> 4
> > > bytes of data. I tried using an array and still get Type Mismatch.
> Thanks
> > > for any advice you can provide.

> > > Kenny



> > > > Looks like a 4 byte REG_BINARY value.

> > > > When you RegRead any key or named value with a REG_BINARY value, you
> get
> > > an array of variants of
> > > > subtype byte with one element per byte.  This is for WSH 2.0 - WSH
1.0
> > > gave you an array of bytes
> > > > (not variants of subtype byte) that was much more difficult to deal
> > > with...

> > > > --
> > > > Michael Harris
> > > > Microsoft MVP - Scripting


message

> > > > > I am having some trouble trying to read certain values from the
> Windows
> > > 98
> > > > > Registry. I have read the WSH documentation from MS and have found
> that
> > > > > RegRead works only with certain data types. I keep getting Type
> Mismatch
> > > > > errors when I try to read the following value:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explore

- Show quoted text -

Quote:
> > > > > r\NoDriveTypeAutoRun

> > > > > The value shows up as 95 00 00 00 when using Regedit. There are no
> > > quotes
> > > > > around the data, it is a numeric data type of some kind. I need to
> be
> > > able
> > > > > to read this information and change it if necessary.

> > > > > I am assuming this is a limitation of WSH, but there has got to be
> > > another
> > > > > way to get this information into/out of the registry using
> scripting.

> > > > > If anyone knows of a method to read and write this type of data
from
> and
> > > to
> > > > > the registry using VBScript and/or WSH, your help would be GREATLY
> > > > > APPRECIATED!

> > > > > TIA,

> > > > > Kenny



Wed, 29 Jan 2003 03:00:00 GMT  
 RegWrite large Binary values to the registry
The only way I have seen to do this is to write a routine that takes a key
and an array of variants and writes the info to a REG files and then run
REGEDIT /S on the REG file.

It's a painful way to do it but other than creating a COM object to do it
(and I'm sure someone has done this already) there is no native way of doing
it with VBScript.

Let me know if you want a sample of the code I use...
brett.nospam.armistead(at)nospam.edt.nospam.ericsson.nospam.se... and I will
send you something. I don't have the code with me at the moment.

regards,
Brett.

Quote:

>I have posted the following questions in a prior thread and the information
>Michael Harris gave works great on writing bytes to the registry. However,
>it works for 7 bytes or less.

>My question now is, I have the need to write Binary Data to the registry,
>and many of these Binary Values are 16 bytes or longer. I have no problem
>reading the values, they read into an array of variants as described by
>Michael. How can I write these long Binary values back to the registry?
CLng
>(x) only works on Hex numbers 7 bytes long or less. Michael, if you can
>help, your reply is greatly appreciated. Attached is our prior
conversation.

>TIA

>Kenny



Sat, 15 Feb 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to write binary value to registry with RegWrite

2. RegWrite Binary value from registry

3. Inserting a binary value into the registry using the RegWrite method

4. Inserting a binary value into the registry using the RegWrite method

5. Format of regWrite binary values

6. Regwrite Binary Value

7. RegWrite Binary Values

8. Reading binary registry values using regobj.dll

9. How to write the binary values to the registry using vbs

10. Need help on writing binary value to registry

11. Registry Keys with Binary Values

12. Reading Binary Registry Values

 

 
Powered by phpBB® Forum Software