[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Is User member of a given group? - ADSI

Posted on 2004-10-28
10
Medium Priority
?
690 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:lexicon1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 

Author Comment

by:lexicon1
ID: 12436989
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
 
LVL 48

Expert Comment

by:Mikal613
ID: 12436998
0
 

Author Comment

by:lexicon1
ID: 12439240
Mikal613,

Could you be a little more specific?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:aaarrrgggghhh
ID: 12442693
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
 
LVL 2

Expert Comment

by:aaarrrgggghhh
ID: 12442700
The above seems to work on my PC running windows XP.
0
 

Author Comment

by:lexicon1
ID: 12446026
aaarrrgggghh,
Your solution blows on my XP box on the same line with the same error number as described in my initial post.
0
 

Author Comment

by:lexicon1
ID: 12446031
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
 

Author Comment

by:lexicon1
ID: 12446076
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
 
LVL 1

Accepted Solution

by:
GhostMod earned 0 total points
ID: 12509474
PAQd, 500 points refunded.

GhostMod
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question