All Forums >> [Scripting] >> WSH & Client Side VBScript >> Listing local group users with WMI Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
I have to list users of local groups with WMI. OS is Windows XP. VBScript is as follows:
'On Error Resume Next
' connect to WMI set oSvc = GetObject("winmgmts:root\cimv2")
' loop through each user
strQuery = "ASSOCIATORS OF {Win32_Group.LocalAccount = True} WHERE ResultClass = Win32_UserAccount AssocClass = Win32_GroupUser"
set Users = oSvc.ExecQuery( strQuery,, 48 )
for each user in Users wscript.echo user.name next
The script terminates with error 0x8004103A "Invalid object path". Can anyone help me?
Hmm... something like this maybe?
On Error Resume Next
strComputer = inputbox("Enter the machine name: ","Acme Corp.",".")
Set oWMI = GetObject("winmgmts:{impersonationlevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colItems = oWMI.ExecQuery("Select * from Win32_UserAccount",,48)
For Each objItem in colItems Wscript.Echo "Name: " & objItem.Name Next
Do you want to list local user accounts of all groups on the local box or list users accounts of all local groups on the local box ? Does the machine you running the scripts from belong to a domain ?
The following code will list all user accounts that belongs to the local group (privoded that the local machine belongs to a workgroup only).
Option Explicit Dim host, group, member host = "myhost" For Each group In GetObject("WinNT://" & host) If group.Class = "Group" Then For Each member In group.members WScript.Echo member.name Next End If Next