Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get user full name from Win32_UserAccount

Status
Not open for further replies.

cluM09

Technical User
May 15, 2004
127
US
Hello,

I have a need to use WMI to query the use information from a group either in the domain or in a computer.

I tried the following WMI query, but it failed with (null): 0x8004103A.

Is it possible to use ASSOCIATORS OF query to get the user name and full name with WMI query?

strDomain = "MYDOMAIN"
strGroup = "Mygroup"
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
strQuery = "ASSOCIATORS OF {Win32_Group.Domain = '" & strDomain & "',Name='" & strGroup & "'} " & _
"WHERE ResultClass = Win32_UserAccount"
Set colItems = objWMIService.ExecQuery(strQuery)
For Each objItem in colItems
Wscript.Echo objItem.Name
Next

Thanks.

 
wait are you trying to find group members, find what groups a user is a member of, or what?

-Brandon Wilson
MCSE:Security00/03
MCSA:Messaging00
MCSA:Security03
A+

 
I need to enumerate the users that belong to a group either a domain or a local group.
 
ah ok

any user interaction being planned here, or automatic determination of the group type? i assume manual interaction here since it sounds like it could be ran from anywhere at any given time.

-Brandon Wilson
MCSE:Security00/03
MCSA:Messaging00
MCSA:Security03
A+

 
>strQuery = "ASSOCIATORS OF {Win32_Group.Domain = '" & strDomain & "',Name='" & strGroup & "'} " & _
"WHERE ResultClass = Win32_UserAccount"

Try this instead.
[tt]strQuery = "ASSOCIATORS OF {Win32_Group.Domain = '" & strDomain & "',Name='" & strGroup & "'} " & _
"WHERE [red]AssocClass=Win32_GroupUser[/red] ResultClass = Win32_[red]Account[/red]"[/tt]
 
tsuji,

I tried your suggestion, but I still get the error (null): 0x8004103A.

The following works but it only works when the strDomain is set to the computer name.

strQuery = "ASSOCIATORS OF {Win32_Group.Domain='" & strDomain & "',Name='" & strGroup & "'} " & _
"WHERE AssocClass=Win32_GroupUser Role=GroupComponent ResultClass=Win32_Account"

The properties of Win32_Account class does not contain the FullName but Win32_UserAccount does.

How can I code it so that it will work with both domain and the local computer name?
 
tsuji,

I made a mistake with respect to the Win32_Account class. This class does indeed has the FullName property.

However, when I hit a group inside the local Administrators group instead of a user, it generates an error "the object does not support this property" which is what I would expect. Therefore, I have to find a way to check the object to see if it is an account name or a group name to avoid this error.

 
Why not use the WinNT provider to retrieve this information?

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
>However, when I hit a group inside the local Administrators group instead of a user, it generates an error "the object does not support this property" which is what I would expect. Therefore, I have to find a way to check the object to see if it is an account name or a group name to avoid this error.
Are you explaining why you did as what done in the first post? or you mean you encounter the error after? I don't get it. If you are just explaining the past, ignore my question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top