我正在尝试创建一个注册表项和子项,以便为计算机上的所有用户启用 IE 11 企业模式。这就是我当前用于 VBScript 的内容,但它失败得很厉害(不添加密钥)。我需要一些帮助来纠正这个问题。
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set ObjRegistry = _
GetObject("winmgmts:{impersonationLevel = impersonate}! \\" & _
strComputer & "\root\default:StdRegProv")
strPath = strKeyPath & "\" & strSubPath
strKeyPath = "Software\Policies\Microsoft"
strSubPath = "Internet Explorer\Main\EnterpriseMode"
strName = "Enabled"
ObjRegistry.CreateKey (HKEY_LOCAL_MACHINE, strPath)
ObjRegistry.SetStringValue HKEY_LOCAL_MACHINE, strPath, strName, strValue
MsgBox "Successfully enabled Internet Explorer Enterprise Mode."
End Function
除了您发布的代码示例不完整之外,您的代码还存在多个问题。
-
"winmgmts:{impersonationLevel = impersonate}! \\" & strComputer & "\root\default:StdRegProv"
世界管理协会moniker https://msdn.microsoft.com/en-us/library/windows/desktop/aa389292.aspx安全设置和路径之间包含虚假空格(...! \\...
)。去掉它。
顺便说一句,如果主机名永远不会改变,那么使用主机名变量是没有意义的。
-
strPath = strKeyPath & "\" & strSubPath
你定义strPath
在定义构建路径的变量之前。此外,您的路径组件被定义为字符串文字,因此您可以删除连接和附加变量并简单地定义strPath
作为字符串文字。
-
ObjRegistry.CreateKey (HKEY_LOCAL_MACHINE, strPath)
除非您在子表达式上下文中调用函数/方法/过程,否则不得将参数列表放在括号中。看here http://blogs.msdn.com/b/ericlippert/archive/2003/09/15/52996.aspx更多细节。但是,您可能需要检查方法调用的返回值以查看它们是否成功。
还有FTR,匈牙利记数法 https://en.wikipedia.org/wiki/Hungarian_notation是毫无意义的代码膨胀。不要使用它。
修改后的代码:
Function SetEnterpriseMode(value)
Const HKLM = &h80000002
Set reg = GetObject("winmgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv")
path = "Software\Policies\Microsoft\Internet Explorer\Main\EnterpriseMode"
name = "Enabled"
rc = reg.CreateKey(HKLM, path)
If rc <> 0 Then
MsgBox "Cannot create key (" & rc & ")."
Exit Function
End If
rc = reg.SetStringValue(HKLM, path, name, value)
If rc = 0 Then
MsgBox "Successfully enabled Internet Explorer Enterprise Mode."
Else
MsgBox "Cannot set value (" & rc & ")."
End If
End Function
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)