Add Multi String value to the registry

纵然是瞬间 提交于 2019-12-25 06:31:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!