Is User member of a given group? - ADSI

I use this code to determine if a user is a member of a given group:

http://www.freevbcode.com/ShowCode.asp?ID=797

It works on Win2k, but not on XP.  It blows on this line: Set oGroup = GetObject("WinNT://" & sDomain & "/" & GroupName)  throwing error -2147467259 (800401e4) with the description: "Automation error.  Unspecified error.

I know next to nothing about ADSI.  Tried Google but only found people asking the same question.

thanks.
lexicon1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lexicon1Author Commented:
Here is the code the URL points to:

Public Function IsMember(GroupName As String, UserName As String) As Boolean

'PURPOSE: Determine if user specified by UserName is member
'of Group Specified by GroupName

'Returns: True if user is a member of group
'         False if user is not member of group,
'           User and/or group does not exist,
'           Or an error occurs

'requires: Win2000, ADSI, reference
'   to ActiveDS type library,

Dim oGroup As IADsGroup
Dim oSysInfo As New WinNTSystemInfo

Dim oRoot As IADs
Dim oDomain As IADsDomain
Dim sDomain As String

On Error GoTo ErrHandler

sDomain = oSysInfo.DomainName
Set oGroup = GetObject("WinNT://" & sDomain & "/" & GroupName)
IsMember = oGroup.IsMember("WinNT://" & sDomain & "/" & UserName)

ErrHandler:
Set oSysInfo = Nothing
Set oGroup = Nothing
Set oRoot = Nothing
Set oDomain = Nothing

End Function
0
lexicon1Author Commented:
Mikal613,

Could you be a little more specific?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

aaarrrgggghhhCommented:
Public Function IsMember(GroupName As String, UserName As String) As Boolean

'PURPOSE: Determine if user specified by UserName is member
'of Group Specified by GroupName

'Returns: True if user is a member of group
'         False if user is not member of group,
'           User and/or group does not exist,
'           Or an error occurs

'requires: Win2000, ADSI, reference
'   to ActiveDS type library,

Dim oGroup As IADsGroup
Dim oSysInfo As New WinNTSystemInfo
Dim oMember As IADs

Dim oRoot As IADs
Dim oDomain As IADsDomain
Dim sDomain As String

On Error GoTo ErrHandler

sDomain = oSysInfo.DomainName
Set oGroup = GetObject("WinNT://" & sDomain & "/" & GroupName)
For Each oMember In oGroup.Members
    If oMember.Name = UserName Then
        IsMember = True
        Exit For
    End If
Next

ErrHandler:
Set oSysInfo = Nothing
Set oGroup = Nothing
Set oRoot = Nothing
Set oDomain = Nothing

End Function
0
aaarrrgggghhhCommented:
The above seems to work on my PC running windows XP.
0
lexicon1Author Commented:
aaarrrgggghh,
Your solution blows on my XP box on the same line with the same error number as described in my initial post.
0
lexicon1Author Commented:
Dim oSysInfo As WinNTSystemInfo: Set oSysInfo = New WinNTSystemInfo
Dim sDomain As String: sDomain = oSysInfo.DomainName
Dim oGroup As IADsGroup


If oVersion.IsWinXP Then
Dim User As IADsUser: Set User = GetObject("WinNT://" & sDomain & "/" & p_sUserName & ",user")
For Each oGroup In User.Groups
    If p_sGroupName = oGroup.Name Then
      bReturn = True
      Exit For
    End If
Next
0
lexicon1Author Commented:
Opps, pressed the wrong key ...

This works on my XP box.  It uses a class that detemines what OS is running that I haven't included.
p_sGroupName and p_sUserName are string parameters.

Dim oSysInfo As WinNTSystemInfo: Set oSysInfo = New WinNTSystemInfo
Dim sDomain As String: sDomain = oSysInfo.DomainName
Dim oGroup As IADsGroup

If oVersion.IsWinXP Then
  Dim User As IADsUser: Set User = GetObject("WinNT://" & sDomain & "/" & p_sUserName & ",user")
  For Each oGroup In User.Groups
    If p_sGroupName = oGroup.Name Then
       bReturn = True
       Exit For
    End If  
  Next
Else
  ... logic from IsMember class posted above.
end if
0
GhostModCommented:
PAQd, 500 points refunded.

GhostMod
Community Support Moderator
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.