Link to home
Start Free TrialLog in
Avatar of DVation191
DVation191

asked on

Editing windows registry with vbscript

I have a very basic vbscript I want to use to edit the windows registry. I have all the edits working except for the REG_BINARY keys. I can't figure out how it works...I never seem to get the results I expect.

Take this key for instance:

Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.RegWrite "HKCU\Software\RealVNC\WinVNC4\Password", <value>, "REG_BINARY"

I don't understand what I need to put for <value>. The problem is that I know what I want the value to show in the windows registry: 4c,00,6a,85,17,ee,bf,3d
I've tried 4c,00,6a,85,17,ee,bf,3d with and without quotes, 4c006a8517eebf3d with and without quotes, I even tried the binary conversion of that hex and either the value that shows up in the registry is wrong or I get a vbscript error about a type mismatch. Where am I going wrong here?
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DVation191
DVation191

ASKER

Sorry, "4c,00,6a,85,17,ee,bf,3d" is the value displayed when you export the key to a .reg file, it actually shows up as "4c 00 6a 85 17 ee bf 3d" in the registry

It still needs to be set in as an array if it's binary. That doesnt' change.

Chris
No, I haven't tried WMI yet. I suppose I could use that instead. Can I use vbscript and WMI in the same vbs file? Or do I need to change all my other vbscript lines of code to WMI? What are the WMI commands for REG_SV and the other registry data types?

You can use either or, there's no reason you can't use both. All the bits above were VbScript used to access WMI, so there's no reason they shouldn't work in the same file.

String Values are:

REG_SZ: objRegistry.SetStringValue <Hive>, <Key>, <Value>, <Data>
REG_DWORD: objRegistry.SetDWORDValue
REG_BINARY: objRegistry.SetBinaryValue
REG_MULTI_SZ: objRegistry.SetMultiStringValue
REG_EXPAND_SZ: objRegistry.SetExpandedStringValue

I think that covers them all.

Chris
Took me a while to iron out some of the details, but in the end I have a script that does what I need it to. Thanks.

Glad I could help :)

Chris