问题
This code is part of a bigger application. It is designed to add anew Multi String value to the registry. I have searched all over the net and cannot get a solution to work.
I can do this with a DOS command but cannot seem to do it with VBScript.
This is the VBScrip I have found which supposedly works.
' Create a MultiString Value in the registry.
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\services\WebClient\Parameters"
strValueName = "AuthForwardServerList"
arrStringValues = Array("*.server1.com", "*.server2.com")
oReg.SetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath, _
strValueName,arrStringValues
Thanks In advance.
回答1:
You need to run your script as administrator.
If you check the SetMultiStringValue return value like this:
res = oReg.SetMultiStringValue(HKEY_LOCAL_MACHINE, strKeyPath, strValueName, arrStringValues)
WScript.Echo res
you get 5 in non-elevated mode, meaning "Access is denied" (see System Error Codes in MSDN).
来源:https://stackoverflow.com/questions/23603499/add-multi-string-value-to-the-registry