Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old September 24th, 2008, 02:29 PM
Newbie
 
Join Date: Aug 2008
Posts: 12
Default Active Directory groups lookup

I'm trying to develop a page which will grab a few details for the currently logged-in Windows user from the Active Directory controller.

I can get the full name of the user from their username without any problems.

What I can't do is find out which groups the user belongs to. The end result will hopefully be a method to ascertain whether the current user is a member of the 'mod' group, the 'admin' group, or neither.

I've tried a few different things, but I just can't find the lookup query for it. Most of the sites I've found so far seem to be aimed at ASP.NET, but my directory/database access skills really aren't good enough to understand what they're doing, why they're doing it, or how to port it back to Classic ASP.

Here's the current code (slightly modified).

Expand|Select|Wrap|Line Numbers
  1. Dim adoCommand, conn, adoRecordSet, currentUser
  2.  
  3. currentUser = Request.ServerVariables("LOGON_USER")
  4.  
  5. Set conn = Server.CreateObject("ADODB.Connection")
  6. conn.Provider = "ADsDSOObject"
  7. conn.Properties("User ID") = "xxx"
  8. conn.Properties("Password") = "yyy"
  9. conn.Properties("Encrypt Password") = True
  10. conn.Open
  11.  
  12. Set adoCommand = Server.CreateObject("ADODB.Command")
  13. adoCommand.ActiveConnection = conn
  14. adoCommand.CommandText = "SELECT cn FROM 'LDAP://ou=USERS,ou=PRNTEST,dc=domain,dc=extension' WHERE ObjectClass='User' AND sAMAccountName='" & currentUser & "' ORDER By cn"
  15.  
  16. Set adoRecordSet = adoCommand.Execute
  17.  
  18. Session("currentUser") = adoRecordSet(0)
I know there are a few different methods to access the Active Directory, but this was the one I understood the most, having done a tiny bit of MySQL.

Some of the sites I've seen seem to imply there is a 'memberof' attribute of the user record, but the entire query above (SELECT * FROM) doesn't show anything like that, just the hierarchy of OUs to the CN.

So, how should I go about checking the AD group memberships for a given user? Is the SQL-type query going to work, or do I need to try a different approach?

Thanks in advance.

Last edited by Zetten; September 24th, 2008 at 02:30 PM. Reason: Tidying code
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 204,860 network members.