Home > Archive > Visual Basic Enterprise > September 2005 > Re: Need code examples as to how to determine what AD groups a user is a member of
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Need code examples as to how to determine what AD groups a user is a member of
|
|
| Mark Yudkin 2005-09-14, 3:58 am |
| Getting the OU is the easiest part - that's what IADsADSystemInfo is all
about. IadsNameTranslate also makes it easy to get from one name to another.
In your case, the string looks wrong, and since hardcoding such strings is
anyway "a very bad idea", you should start by fixing that logic.
Sample code to do what you want (all of your cases) can be found in the MSDN
library (http://msdn.microsoft.com/library) in the section on "Using Active
Directory".
The LDAP MemberOf attribute will get the Groups a user is a "MemberOf".
"Rod" <rodf@newsgroups.nospam> wrote in message
news:%23CRYMELuFHA.4080@TK2MSFTNGP12.phx.gbl...
> I've been trying to modify one of our older VB6 applications to be able to
> determine if the user running the application is a member of a group in
> Active Directory (this is on a Windows 2000 AD domain). In order to gain
> some experience at this I have tried to at least list all users within AD,
> or an organizational unit in AD, and even that doesn't work. I am
> including a reference to "Active DS Type Library", but even so it doesn't
> seem to work. Here's the code I've got so far:
>
> ******************
> Dim container As IADsContainer
> Dim user As IADsUser
> Dim obj As Object
> Dim sTmp As String
>
> Set container =
> GetObject("LDAP://MY_SERVER/OU=MY_OU,DC=mycompany,DC=com")
>
> For Each user In container
> sTmp = txtUsers.Text 'txtUsers is a textbox on the form
> sTmp = sTmp & vbCrLf & user.Name
> txtUsers.Text = sTmp
> Next user
>
> Set container = Nothing
>
> ******************
>
> As I said, the above doesn't work, and I'm not sure why.
>
> Even if it did work, eventually I want to determine what groups the logged
> in user is a member of, so how would I find out what groups he/she is a
> member of?
>
> Rod
>
>
| |
|
| Mark,
I agree with you that hard coding a string isn't a good idea, but in the
case of the AD and server involved, since I know what they are and they
aren't going to change soon, why is that bad? But more to your point, how
would you suggest that I programmatically determine the server, OU, etc?
And than you for recommending which search string to use in MSDN library.
Rod
"Mark Yudkin" <myudkinATcompuserveDOTcom@boingboing.org> wrote in message
news:%23vQoOSPuFHA.908@tk2msftngp13.phx.gbl...
> Getting the OU is the easiest part - that's what IADsADSystemInfo is all
> about. IadsNameTranslate also makes it easy to get from one name to
> another. In your case, the string looks wrong, and since hardcoding such
> strings is anyway "a very bad idea", you should start by fixing that
> logic.
>
> Sample code to do what you want (all of your cases) can be found in the
> MSDN library (http://msdn.microsoft.com/library) in the section on "Using
> Active Directory".
>
> The LDAP MemberOf attribute will get the Groups a user is a "MemberOf".
>
> "Rod" <rodf@newsgroups.nospam> wrote in message
> news:%23CRYMELuFHA.4080@TK2MSFTNGP12.phx.gbl...
>
>
| |
| Mark Yudkin 2005-09-15, 3:58 am |
|
"Rod" <rodf@newsgroups.nospam> wrote in message
news:eqdsCRTuFHA.3528@TK2MSFTNGP15.phx.gbl...
> Mark,
>
> I agree with you that hard coding a string isn't a good idea, but in the
> case of the AD and server involved, since I know what they are and they
> aren't going to change soon, why is that bad?
Everything always changes - especially server names, and when it does,
you've forgotten that you weren't prepared. Moreover, since this sort of
hardcoding is hardly shorter than doing it right, why go out of you way to
hardcode the string? Especially as yours actually looks wrong to me?
> But more to your point, how would you suggest that I programmatically
> determine the server, OU, etc?
By using IADsADSystemInfo (and IadsNameTranslate), as I already said.
>
> And than you for recommending which search string to use in MSDN library.
>
> Rod
>
> "Mark Yudkin" <myudkinATcompuserveDOTcom@boingboing.org> wrote in message
> news:%23vQoOSPuFHA.908@tk2msftngp13.phx.gbl...
>
>
|
|
|
|
|