无法使WMI命名空间RSOP工作

时间:2012-08-16 15:01:49

标签: vbscript wmi

我需要创建一个子程序来检查系统上的某些策略。我目前正在尝试这样做。

strComputerFQDN是在程序开头定义的,工作正常。

你看错了什么吗?

这是我的代码:

'*************************************************************************
' This Subroutine checks Local Policies
'*************************************************************************
Sub CheckPolicies()
   Dim objGPOSrvc,colItems,objItem
   Set objGPOSrvc = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerFQDN & "\root\RSOP")
   Set colItems = objGPOSrvc.ExecQuery("SELECT * FROM RSOP_GPO")

   WScript.Echo("Check Policies")
   WScript.Echo("------------------------------------")

   For Each objItem in colItems
      If InStr(UCase(objItem.Name),"WSUS") Then
         If InStr(UCase(objItem.Name),"SERVER") Then
            WScript.Echo("Policy applied: " & objItem.Name)
         Else
            WScript.Echo("Wrong WSUS Policy Applied - Check Computer object location")
         End If
      End If
   Next
   If strWSUSApplied = "FALSE" Then
      WScript.Echo("No WSUS Policy Applied!")
   End If
   WScript.Echo vbCrLf
End Sub

1 个答案:

答案 0 :(得分:2)

名称空间应为root\RSOP\Computer

Set objGPOSrvc = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerFQDN & "\root\RSOP\Computer")

root\RSOP\User

Set objGPOSrvc = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerFQDN & "\root\RSOP\User")

最常见的是你会做这样的事情:

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\RSOP\Computer")
Set colItems = objWMIService.ExecQuery("Select * from RSOP_GPO")
For Each objItem in colItems  
    WScript.Echo "Name: " & objItem.Name
    WScript.Echo "GUID Name: " & objItem.GUIDName
    WScript.Echo "ID: " & objItem.ID
    WScript.Echo "Access Denied: " & objItem.AccessDenied
    WScript.Echo "Enabled: " & objItem.Enabled
    WScript.Echo "File System path: " & objItem.FileSystemPath
    WScript.Echo "Filter Allowed: " & objItem.FilterAllowed
    WScript.Echo "Filter ID: " & objItem.FilterId
    WScript.Echo "Version: " & objItem.Version
    WScript.Echo
Next

如果收到错误0x80041003,则需要使用管理员凭据运行此脚本。对于Vista及更高版本,请打开开始菜单并输入cmd。出现“命令提示符”时,右键单击并选择“以管理员身份运行”。您现在可以从提升的命令提示符启动脚本而不会出错。