[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2553
  • Last Modified:

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?
0
DVation191
Asked:
DVation191
  • 4
  • 3
1 Solution
 
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
0
 
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
0
 
Chris DentPowerShell DeveloperCommented:

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

Chris
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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?
0
 
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
0
 
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.
0
 
Chris DentPowerShell DeveloperCommented:

Glad I could help :)

Chris
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now