Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Listing local group users with WMI

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2048
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
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!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Listing local group users with WMI - 2/13/2005 8:26:22 PM   
  beegee

 

Posts: 1
Score: 0
Joined: 2/9/2005
From:
Status: offline
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?
 
 
Post #: 1
 
 Re: Listing local group users with WMI - 2/14/2005 1:00:33 AM   
  sambuca

 

Posts: 8
Score: 0
Joined: 1/3/2005
From:
Status: offline
quote:
Originally posted by beegee

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

(in reply to beegee)
 
 
Post #: 2
 
 Re: Listing local group users with WMI - 2/14/2005 1:16:42 AM   
  tnoonan

 

Posts: 364
Score: 0
Joined: 12/14/2004
From:
Status: offline
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_Group Where LocalAccount = True")
For Each objItem in colItems
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "Domain: " & objItem.Domain
Wscript.Echo "Local Account: " & objItem.LocalAccount
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "SID: " & objItem.SID
Wscript.Echo "SID Type: " & objItem.SIDType
Wscript.Echo "Status: " & objItem.Status
Wscript.Echo
Next

(in reply to beegee)
 
 
Post #: 3
 
 Re: Listing local group users with WMI - 2/16/2005 3:35:46 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
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

(in reply to beegee)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Listing local group users with WMI Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts