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?
LVL 20
DVation191Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:

Have you tried WMI instead?

Const REG_HKCR = &H80000000
Const REG_HKCU = &H80000001
Const REG_HKLM = &H80000002

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

strKeyPath = "Software\RealVNC\WinVNC4\Password"
strValue = "<ValueName>"
arrData = Array(&H4C, &H00, &H6a, &H85, &H17, &HEE, &HBF, &H3D)

objRegistry.SetBinaryValue REG_HKCU, strKeyPath, strValue, arrData

Chris

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DVation191Author Commented:
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
Chris DentPowerShell DeveloperCommented:

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

Chris
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

DVation191Author Commented:
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?
Chris DentPowerShell DeveloperCommented:

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
DVation191Author Commented:
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.
Chris DentPowerShell DeveloperCommented:

Glad I could help :)

Chris
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.