none
Win32_GroupUser namespace is incomplete on Windows Server 2003 RRS feed

  • Question

  • Hello.

    I have VBS script that fetches members of local administrator group. 

    It works fine on all versions since 2008 or higher, but on windows server 2003 it doesn't get one domain group, that does exist in local administrators group.

    I see that group in GUI, but it doesnt exist in namespace Win32_GroupUser. Why?

    Sub GetAdministrators(strComputerName)
        Dim objWMIService, strQuery, colItems, Path, strMembers
        groupname = ""
        domain = "."
        sid ="S-1-5-32-544"
        Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        qry = "SELECT * FROM Win32_Group WHERE Domain = ""."" and SID=""S-1-5-32-544"""
        For Each group In objWMIService.ExecQuery(qry)
        groupname = group.Name
        Next
        strQuery = "select * from Win32_GroupUser where GroupComponent = " & chr(34) & "Win32_Group.Domain='" & strComputerName & "',Name='" & groupname & "'" & Chr(34)
        Set ColItems = objWMIService.ExecQuery(strQuery)
        strMembers = ""
        For Each Path In ColItems
            Dim strMemberName, NamesArray, strDomainName, DomainNameArray
            NamesArray = Split(Path.PartComponent,",")
            strMemberName = Replace(Replace(NamesArray(1),Chr(34),""),"Name=","")
            DomainNameArray = Split(NamesArray(0),"=")
            strDomainName = Replace(DomainNameArray(1),Chr(34),"")
            If strDomainName <> strComputerName Then
                strMemberName = strDomainName & "\" & strMemberName
            End If
            WScript.Echo strMemberName
        Next
    End Sub
     
    Function GetComputerName()
        Set objWMISvc = GetObject( "winmgmts:\\.\root\cimv2" )
        Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
        For Each objItem in colItems
            strComputerName = objItem.Name
            GetComputerName = strComputerName
        Next
    End Function
     
    GetAdministrators GetComputerName()
    Sunday, September 17, 2017 1:28 PM

All replies

  • This is the VB.NET forum not a VBS forum.

    I suggest that you find a VBS forum.

    Sunday, September 17, 2017 1:55 PM
  • Hi pawellrus,

    Since this forum is discussing and asking questions about the Visual Basic programming language, IDE, libraries, samples, and tools . And your issue is more related to VBS. This link about vbs, please refer that:

    https://social.technet.microsoft.com/Forums/scriptcenter/en-us/home?forum=ITCG

    Thank you for participating in the forum activities.

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 18, 2017 2:31 AM