1

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

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
4

1 回答 1

3

命名空间应该是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. 出现“命令提示符”时,右键单击并选择以管理员身份运行。您现在可以从提升的命令提示符启动脚本而不会出错。

于 2012-08-16T17:56:29.850 回答