naqayya
asked on
Get Win NT Group for current User
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.
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.
ASKER
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.
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.
VB-VBA is almost the same. You could open the frm,bas and cls files with Notepad.
ASKER
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(strUsern ame) 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.
Public Sub RemoveUser(strUsername, strGroup, strDomain)
Dim adsGroup As ActiveDs.IADsGroup
Set adsGroup = GetObject("WinNT://" + strDomain + "/" + strGroup)
If adsGroup.IsMember(strUsern
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.
You need to set a reference to Active DS type library first (activeds.tlb)
ASKER
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.
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.
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Richie.
I need a function that returns the Group name that the current User belongs to.
I need a function that returns the Group name that the current User belongs to.
With preceding code, you have to pass group names and username to function until it returns True.
ASKER
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).
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).
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
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
ASKER
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!
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!
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.
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.
ASKER
Could you show me the code to do that please?
Thanks.
Thanks.
ASKER
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!!
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!!
Glad to here that and thanks for "A" grade.
Sorry for not to have too much time to help you more.
Cheers
Sorry for not to have too much time to help you more.
Cheers
Richie, you the man. This is exactly what I needed. Thank you, sir.
You are welcome.
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?
it suppose to, i think. did you check those links?
Sorry - have since got that to work....but forgot to post another comment.
Thanks very much for getting back to me
Thanks very much for getting back to me
http://www.vbsquare.com/demos/adsi-demo/index.html