Envin
Envin

Reputation: 1523

Can't get WMI namespace RSOP to work

I need to create a subroutine to check for certain policies on a system. I'm currently just trying to do that.

strComputerFQDN is defined at the beginning of the program and that is working fine.

Do you see anything wrong?

Here is my code:

'*************************************************************************
' 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

Upvotes: 1

Views: 3369

Answers (1)

Nilpo
Nilpo

Reputation: 4816

The namespace should be root\RSOP\Computer

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

or root\RSOP\User

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

Most typically you would do something like this:

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

If you receive Error 0x80041003, you will need to run this script with administrator credentials. For Vista and later, open your start menu and type cmd. When "Command Prompt" appears, right-click and choose Run As Administrator. You can now launch your script from the elevated command prompt without error.

Upvotes: 3

Related Questions