Solved

Get Win NT Group for current User

Posted on 2002-05-14
23
487 Views
Last Modified: 2008-02-26
I want to hide a button on a Form for Users that belong to a certain Windows NT Group.

I need to know an easy way to find out which Win NT Group the current User belongs to.

Can someone show me the VBA code to do this?

Thanks.
0
Comment
Question by:naqayya
[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
  • 11
  • 9
  • 2
  • +1
23 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7009746
Take a look at this great code:
http://www.vbsquare.com/demos/adsi-demo/index.html
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7009755
0
 

Author Comment

by:naqayya
ID: 7010426
Thanks Richie:

I haven't got Visual Basic, only the VBA application that comes with Access 2000, so I don't know how to open the files. I'm a bit of a novice so please could you tell me which file has the code that I need and how I could use that code behind my Form.

Thanks again.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7011095
VB-VBA is almost the same. You could open the frm,bas and cls files with Notepad.
0
 

Author Comment

by:naqayya
ID: 7011199
I tried pasting the following code in my module:

Public Sub RemoveUser(strUsername, strGroup, strDomain)

Dim adsGroup As ActiveDs.IADsGroup

  Set adsGroup = GetObject("WinNT://" + strDomain + "/" + strGroup)
  If adsGroup.IsMember(strUsername) Then
    adsGroup.Remove "WinNT://" + strDomain + "/" + strGroup + "/" + strUsername
  End If

End Sub


I get a compile error for the Dim line saying 'User-defined type not defined'.

Can you help? Is this the right code? Are these 2 lines sufficient?

Dim adsGroup As ActiveDs.IADsGroup

Set adsGroup = GetObject("WinNT://" + strDomain + "/" + strGroup)

Thanks.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7011311
You need to set a reference to Active DS type library first (activeds.tlb)
0
 

Author Comment

by:naqayya
ID: 7011356
I have set the reference.

Could you tell me what changes I have to make to the code so that I can have a function that returns the Win NT Group for the current User?

Thanks.
0
 

Author Comment

by:naqayya
ID: 7011448
I have set the reference.

Could you tell me what changes I have to make to the code so that I can have a function that returns the Win NT Group for the current User?

Thanks.
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 300 total points
ID: 7011514
Well, i never used it and since we have Linux here, i can't try it, but i supossse that this should works:
' function returns false if memeber doesn't belongs to group, otherwise True

Public Function MembersOfGroup(strGroup, strDomain, strMember As String) As Boolean
Dim adsGroup As ActiveDs.IADsGroup
Dim adsMembers As ActiveDs.IADsMembers
Dim adsMember As Object
       
On Error Resume Next
Set adsGroup = GetObject("WinNT://" + strDomain + "/" + strGroup)
MembersOfGroup = False
If Err.Number = 0 Then
    Err.Clear
    On Error GoTo 0
    Set adsMembers = adsGroup.Members
    Set oCol = New Collection
    adsMembers.Filter = Array("Members")
    For Each adsMember In adsMembers
        If adsMember.Name = strMember Then
            MembersOfGroup = True
            Exit For
        End If
    Next adsMember
    Set adsMember = Nothing
    Set adsMembers = Nothing
    Set adsGroup = Nothing
End If

End Function
0
 

Author Comment

by:naqayya
ID: 7019387
Thanks Richie.

I need a function that returns the Group name that the current User belongs to.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7023011
With preceding code, you have to pass group names and username to function until it returns True.
0
 

Author Comment

by:naqayya
ID: 7023366
Thanks again Richie.

This could be a problem. I can get the current UserName and pass it to your function, so that is OK, but I will have to pass each and every Group. If we change the Group names or add/remove Groups then the code will have to be changed each time. I would rather not have this extra maintenance for the code.

Is there no way that I can pass the current UsetrName and get the Group name?

Thanks Richie (sorry to to pester you).
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7023917
i don't know how did you implement that, but if you don't pass username, code shouldn't know to which user we are talking about.
If you add/remove groups... we are stored their names?
In an INI file?, a database? Being dynamic, their must be sotored outside the main program (i mean, on another file than the executable itself), program should read that file and act accordingly, what do you think?
i'll be waiting...
Cheers
0
 

Author Comment

by:naqayya
ID: 7023952
Of course, we have to pass the UserName (and maybe Domain also).
But I want a function in which I don't have to pass the Group name.
The function should get the Group name from Windows. I don't know where Windows stores the Group names and members though.

Anu ideas? Thanks!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7024082
Point well stated!.
Afaik, we need to continue using ADSI to enumerate all groups for a given domain, then in each "lap" of that enumeration, pass the group name with username until we got return true value.
0
 

Author Comment

by:naqayya
ID: 7024118
Could you show me the code to do that please?

Thanks.
0
 

Author Comment

by:naqayya
ID: 7032996
Richie:

Hey, your code works! I tested it out today and it's perfect!

Please forgive me for taking so long, and thanks for your patience with me.

Thanks again!!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7033325
Glad to here that and thanks for "A" grade.
Sorry for not to have too much time to help you more.
Cheers
0
 
LVL 1

Expert Comment

by:rbsnow
ID: 7614589
Richie, you the man.  This is exactly what I needed.  Thank you, sir.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7624051
You are welcome.
0
 
LVL 7

Expert Comment

by:arduk
ID: 7679355
Am trying to find out how to list the names of members of a Win 2000 user group, and came across your code. Do you konw if this will work with win 2000?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7681519
it suppose to, i think. did you check those links?
0
 
LVL 7

Expert Comment

by:arduk
ID: 7681551
Sorry - have since got that to work....but forgot to post another comment.

Thanks very much for getting back to me
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

726 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