if its NT then use the WinNT provider and bind to the Group and then iterate through it, you will find tonnes of examples if you seach for them in this forum, infact you might find a FAQ on it
Set User = GetObject("WinNT://domainX/" & strUser & ",user")
Set Group = GetObject("WinNT://domainX/" & strGroup &",group")
wscript.echo Group.IsMember(User.ADsPath)
or.
Set User = GetObject("WinNT://domainX/" & strUser & ",user")
For Each aGroup In User.Groups
If aGroup.Name = "mygroup" Then
Wscript.Echo "they are"
End If
Next
what have you got yourself? are you working on a script? do you want to post your work and share with the rest of us?
I work in NT network. This is the code inspired on code that's found on the web.
----------------------------------
Private Function IsMember(groupName)
Dim NetObj, UserObj, Grp
Dim Domain, user, flgIsMember
Set netObj = CreateObject("WScript.Network")
domain = netObj.UserDomain
user = netObj.UserName
flgIsMember = 0
Set userObj = GetObject("WinNT://" & domain & "/" & user & ",user")
For Each grp In userObj.Groups
If UCASE(grp.Name) = UCASE(groupName) Then
flgIsMember = 1
Exit For
End If
Next
IsMember = flgIsMember
Set userObj = nothing
Set netObj = nothing
youre welcome for the help!
no offense but im in crap mode today so here are my thoughts.
1. it only works in the context of the currently logged on user
2. everytime you want to query if a user is a member of a groups it is going to
+ create a wscript.network object
+ retrieve domainname
+ retrieve username
+ bind to a user object
+ run through a collection of groups
so, from point 1. i guess you are using this for a logon script? either way it still sucks.
lets say you want to check if the user is a member of 5 groups,,,please dont tell me you are going to call this function 5 times,,,
5 X create a wscript.network object
5 X retrieve domainname
5 X retrieve username
5 X bind to a user object
5 X run through a collection of groups
vbscript is very powerful, but also very dangerous and seriously slow when inspiration is involved ;-)
so, ok what is the answer.
loop through the .Groups collection once. when looping through add each group.name to a dictionary object. have the function return a dictionary object to your calling script.
therefore from then on you have it in memory and all you have to do is
dicGroups.Exists("groupnameofinterest")
no more binding to objects and users which will speed things up in the long run.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.