Reputation: 3331
I'm using the examples from technet to try to read a dword / string from HKLM\Microsoft\Windows\CurrentVersion\Run called MyStartupExe.. It is returning empty.. This regular example works:
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set oReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "Console"
strValueName = "HistoryBufferSize"
oReg.GetDWORDValue _
HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
WScript.Echo "Current History Buffer Size: " & dwValue
My adaptation of it does not work. The string and dword value exists in the registry at the key path I'm looking for.
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
strValueName = "MyStartUpExe"
oReg.GetDWORDValue _
HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
WScript.Echo "MyStartupExe" & dwValue
Upvotes: 0
Views: 4177
Reputation: 271
Refer to the WMI StdRegProv class.
Or you could just use Shell.RegRead
to read registry values where you don't know the values' datatype. If the return code of RegRead
is 0 (success) a reg value exists, else if the return code will be some general error code, e.g. &h800xxxxx
etc. then no reg value exists. To check your OS architecture type, query the Win32_Processor.Architecture
value (where '0' = 'x86' or '9' = 'x64').
Upvotes: 0
Reputation: 200233
"MyStartUpExe" is most likely a REG_SZ
value, not a REG_DWORD
value, so you'll have to use GetStringValue()
instead of GetDWORDValue()
.
oReg.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, value
WScript.Echo "MyStartUpExe" & value
Upvotes: 1