Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Copy a binary registry value to another value.

Reply
 
Old 09-03-2009   #1 (permalink)
Oldguard


 
 

Copy a binary registry value to another value.

I need to copy the contents of a binary value to another location in the
registry. For example:

set oShell = CreateObject("Wscript.Shell")
Key1 = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet
Settings\Connections\DefaultConnectionSettings"
Key2 = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet
Settings\Connections\Connection1"
TransferSetting = oShell.RegRead (Key1)
oShell.RegWrite Key2,TransferSetting,"REG_BINARY"

Everything works until I do the write portion of this script. Than I get
type mismatch presumably because the key has been saved as a string instead
of as a binary value. I need to copy the binary value to more than one
location, and the name of the destintation is not consistant, so other
methods like using a reg file are not an option. Anyone have an idea on how
to do this?

My System SpecsSystem Spec
Old 09-03-2009   #2 (permalink)
mayayana


 
 

Re: Copy a binary registry value to another value.

WScript.Shell Registry functions are rather limited.
The hack used in the past for binary has been to
export the key, edit the text file, then re-import.
Very messy.

You can do get fairly complete Registry functionality
using WMI through VBScript. (WMI is generally pre-installed
and running on all Windows PCs since at least WinME.
I'm not sure about Win2000. It can be installed on Win98.)

The WMI functions are badly designed, and WMI itself
is very slow and clunky. But it works. See here for sample
code:
www.jsware.net/jsware/scripts.php5#wmirclas

The download is a VBScript class that's designed to make
WMI Registry functions easier. It hides the WMI StdRegProv
Registry functions mess inside the class and provides clear,
simple functions like GetValue, SetValue, EnumKeys, etc.
(If you haven't used classes before.... you can just paste the
class at the end of your script -- or load it from an external
file and call ExecuteGlobal on it -- and then create an instance
of the class as an object.)

Quote:

> I need to copy the contents of a binary value to another location in the
> registry. For example:
>
> set oShell = CreateObject("Wscript.Shell")
> Key1 = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet
> Settings\Connections\DefaultConnectionSettings"
> Key2 = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet
> Settings\Connections\Connection1"
> TransferSetting = oShell.RegRead (Key1)
> oShell.RegWrite Key2,TransferSetting,"REG_BINARY"
>
> Everything works until I do the write portion of this script. Than I get
> type mismatch presumably because the key has been saved as a string
instead
Quote:

> of as a binary value. I need to copy the binary value to more than one
> location, and the name of the destintation is not consistant, so other
> methods like using a reg file are not an option. Anyone have an idea on
how
Quote:

> to do this?

My System SpecsSystem Spec
Old 09-03-2009   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: Copy a binary registry value to another value.

All versions of Windows 2000 come with WMI. As I recall, it must be
installed on NT.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"mayayana" <mayaXXyana@xxxxxx> wrote in message
news:O$O3k$JLKHA.4516@xxxxxx
Quote:

> WScript.Shell Registry functions are rather limited.
> The hack used in the past for binary has been to
> export the key, edit the text file, then re-import.
> Very messy.
>
> You can do get fairly complete Registry functionality
> using WMI through VBScript. (WMI is generally pre-installed
> and running on all Windows PCs since at least WinME.
> I'm not sure about Win2000. It can be installed on Win98.)
>
> The WMI functions are badly designed, and WMI itself
> is very slow and clunky. But it works. See here for sample
> code:
> www.jsware.net/jsware/scripts.php5#wmirclas
>
> The download is a VBScript class that's designed to make
> WMI Registry functions easier. It hides the WMI StdRegProv
> Registry functions mess inside the class and provides clear,
> simple functions like GetValue, SetValue, EnumKeys, etc.
> (If you haven't used classes before.... you can just paste the
> class at the end of your script -- or load it from an external
> file and call ExecuteGlobal on it -- and then create an instance
> of the class as an object.)
>
>
Quote:

>> I need to copy the contents of a binary value to another location in the
>> registry. For example:
>>
>> set oShell = CreateObject("Wscript.Shell")
>> Key1 = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet
>> Settings\Connections\DefaultConnectionSettings"
>> Key2 = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet
>> Settings\Connections\Connection1"
>> TransferSetting = oShell.RegRead (Key1)
>> oShell.RegWrite Key2,TransferSetting,"REG_BINARY"
>>
>> Everything works until I do the write portion of this script. Than I get
>> type mismatch presumably because the key has been saved as a string
> instead
Quote:

>> of as a binary value. I need to copy the binary value to more than one
>> location, and the name of the destintation is not consistant, so other
>> methods like using a reg file are not an option. Anyone have an idea on
> how
Quote:

>> to do this?
>
>

My System SpecsSystem Spec
Old 09-03-2009   #4 (permalink)
mr_unreliable


 
 

Re: Copy a binary registry value to another value.

Oldguard wrote:
Quote:

> I need to copy the contents of a binary value to another location in the
> registry.
hi OldGuard,

Instead of using RegRead/Write, I suggest using wmi's
"StdRegProv" class, as follows:

Set objRegistry = GetObject("winmgmts:root\default:StdRegProv")

From there, you have access to the "GetBinaryValue" and
"SetBinaryValue" methods, which might work better for what
you want to do. Here is some documentation:

http://msdn.microsoft.com/en-us/libr...64(VS.85).aspx

Also, there are some example scripts to be found in
this ng. Use "advanced group search" and look for
"default:StdRegProv" and "GetBinaryValue".

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Adding new String and Binary valules to registry PowerShell
how to write/change binary value in registry VB Script
64 bit binary or (-bor operator)? PowerShell
How to embed manifest in TCL binary? - mt.exe corrupting my binary Vista General
Copy-Item or Copy-ItemProperty and Remote Registry. PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46