Reputation: 9
I want to read a REG_DWORD to put the information in BGinfo with a VBS file
I do this script but not works
Const HKEY_USERS=&H80000003
strComputer = "."
DW="tct"
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "HKEY_USERS\S-1-5 20\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Settings"
strValueName = "DownloadMode"
oReg.GetDWORDValue HKEY_USERS,strKeyPath,strValueName,dwValue
dw="t "& swValue
msgbox DW
In message box show t but not swValue
I'm interested to show the values into DownloadMode if it 0 or 1, to registry automatically in the field of Bginfo data access
what am I doing wrong?
Upvotes: -1
Views: 721
Reputation: 9
I found it the problem was in strKeyPath = "HKEY_USERS\S-1-5 20\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Settings it's wrong you have to put strKeyPath = "S-1-5 20\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Settings" without HKEY_USERS
Upvotes: 0
Reputation: 1983
User S-1-5-20 is the Network Service account. Your script has to be running with elevated privileges to read the values there. To see this for yourself, open a regular Cmd prompt and also open another Cmd prompt as Administrator. Run either one of the following scripts. They will error out under the regular Cmd prompt, but will return the value for DownloadMode (if it exists) under the Administrator Cmd prompt.
Read dword value using RegRead:
Set oWSH = CreateObject("Wscript.Shell")
x = oWSH.RegRead("HKEY_USERS\S-1-5-20\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Settings\DownloadMode")
MsgBox x
Read dword value using WMI:
Const HKEY_USERS=&H80000003
Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
oReg.GetDWORDValue HKEY_USERS,"S-1-5-20\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Settings","DownloadMode",x
MsgBox x
Note: I could not find a reference for a "DownloadMode" dword value under this key. I created the value for the purposes of testing this script. I did find a reference to this key under HKLM with a DownloadMode STRING value and DODownloadMode dword value under a "Config" key. So, be sure that you have the key, valuename, and data type correct.
Upvotes: 1