Search code examples
vbscriptregistrywmi

Can't use VB Script to create registry keys


I can't use VB Script to create registry keys. I've hecked WMI using wbemtest and I am running the script using administrative privileges. I beleive the code is correct - I've seen several sample on the internet and it seems to be straight forward. Is there anything else within the OS that could prevent a VB Script from creating registry keys?

Sample code is below.

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "ostslhqe-48958" 

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

strKeyPath = "SOFTWARE\TestKey"

objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath

strKeyPath = "SOFTWARE\Script Center"

objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath

Solution

  • An example of registry entry creation would be:

    Const HKEY_CURRENT_USER = &H80000001
    strComputer = "."
    Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
    strValueName = "My DWORD Value"
    dwValue = 13
    objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue
    

    Source : http://blogs.technet.com/b/heyscriptingguy/archive/2006/11/16/how-can-i-create-a-new-registry-key.aspx