473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Discussion: Pulling Info from Active Directory

anoble1
245 128KB
Hi,

I am wanting to make a db that pulls user clients info from the network in Active Directory. Has anyone been able to search through Access and connect to Active Directory? Was wanting to do an number of things, like search by User ID, and pull address, phone and computer info, then remotely connect to PC etc.

Thanks,
Nov 9 '12 #1

✓ answered by NeoPa

I have some code that may help :
Expand|Select|Wrap|Line Numbers
  1. 'GetUserObject() returns an IADs object representing either the LDAP: string
  2. '  if passed, or the logged-on user otherwise.
  3. Public Function GetUserObject(Optional ByVal strDN As String = "") As Object
  4.     If strDN > "" Then
  5.         Set GetUserObject = GetObject("LDAP://" & strDN)
  6.     Else
  7.         strDN = "LDAP://OU=MyBusiness," & _
  8.                 GetObject("LDAP://RootDSE").Get("rootDomainNamingContext")
  9.         Set GetUserObject = ProcessIAD(GetObject(strDN), GetLogonName)
  10.     End If
  11. End Function
  12.  
  13. 'ProcessIAD() is called recursively and returns an object only when it is a user
  14. '  that matches strUser.
  15. Private Function ProcessIAD(ByRef iadVar As Object, strUser As String) As Object
  16.     Dim iadWork As Object
  17.  
  18.     With iadVar
  19.         Select Case IADType(iadVar)
  20.         Case "User"
  21.             If .sAMAccountName = strUser Then Set ProcessIAD = iadVar
  22.             Exit Function
  23.         Case "organizationalUnit"
  24.             For Each iadWork In iadVar
  25.                 Set ProcessIAD = ProcessIAD(iadWork, strUser)
  26.                 If Not ProcessIAD Is Nothing Then Exit Function
  27.             Next iadWork
  28.         End Select
  29.     End With
  30. End Function
  31.  
  32. 'IADType() returns whether the IAD should be treated as a container
  33. '  (organizationalUnit), a user (user), or simply ignored (group).
  34. Private Function IADType(iadVar As Object) As String
  35.     Dim varWork As Variant
  36.  
  37.     With iadVar
  38.         Call .GetInfo
  39.         For Each varWork In .Get("objectClass")
  40.             Select Case varWork
  41.             Case "user", "group", "organizationalUnit"
  42.                 IADType = varWork
  43.                 Exit For
  44.             End Select
  45.         Next varWork
  46.     End With
  47. End Function
The following procedure lists what it finds :
Expand|Select|Wrap|Line Numbers
  1. 'ShowIADs() shows all users, groups and containers of the AD from strRoot.
  2. Public Sub ShowIADs(Optional ByRef iadVar As Object, _
  3.                     Optional ByVal strRoot As String = "")
  4.     Dim iadWork As Object
  5.     Dim strWork As String
  6.  
  7.     If iadVar Is Nothing Then
  8.         strWork = "LDAP://" & _
  9.                   strRoot & _
  10.                   "OU=MyBusiness," & _
  11.                   GetObject("LDAP://RootDSE").Get("rootDomainNamingContext")
  12.         Set iadVar = GetObject(strWork)
  13.     End If
  14.     With iadVar
  15.         strWork = IADType(iadVar)
  16.         If strWork > "" Then
  17.             Debug.Print strWork & "," & _
  18.                         IIf(strWork = "user", .sAMAccountName, "") & "#" & _
  19.                         .distinguishedName & "~";
  20.         End If
  21.         Select Case strWork
  22.         Case "user"
  23.             Exit Sub
  24.         Case "organizationalUnit"
  25.             For Each iadWork In iadVar
  26.                 Call ShowIADs(iadWork)
  27.             Next iadWork
  28.         End Select
  29.     End With
  30. End Sub
I don't think there are any calls in here except to standard procedures. I think most of this is found in the VBA library.

5 8430
Rabbit
12,516 Expert Mod 8TB
I use an LDAP query when I need to pull data from AD.
Nov 9 '12 #2
NeoPa
32,556 Expert Mod 16PB
I have some code that may help :
Expand|Select|Wrap|Line Numbers
  1. 'GetUserObject() returns an IADs object representing either the LDAP: string
  2. '  if passed, or the logged-on user otherwise.
  3. Public Function GetUserObject(Optional ByVal strDN As String = "") As Object
  4.     If strDN > "" Then
  5.         Set GetUserObject = GetObject("LDAP://" & strDN)
  6.     Else
  7.         strDN = "LDAP://OU=MyBusiness," & _
  8.                 GetObject("LDAP://RootDSE").Get("rootDomainNamingContext")
  9.         Set GetUserObject = ProcessIAD(GetObject(strDN), GetLogonName)
  10.     End If
  11. End Function
  12.  
  13. 'ProcessIAD() is called recursively and returns an object only when it is a user
  14. '  that matches strUser.
  15. Private Function ProcessIAD(ByRef iadVar As Object, strUser As String) As Object
  16.     Dim iadWork As Object
  17.  
  18.     With iadVar
  19.         Select Case IADType(iadVar)
  20.         Case "User"
  21.             If .sAMAccountName = strUser Then Set ProcessIAD = iadVar
  22.             Exit Function
  23.         Case "organizationalUnit"
  24.             For Each iadWork In iadVar
  25.                 Set ProcessIAD = ProcessIAD(iadWork, strUser)
  26.                 If Not ProcessIAD Is Nothing Then Exit Function
  27.             Next iadWork
  28.         End Select
  29.     End With
  30. End Function
  31.  
  32. 'IADType() returns whether the IAD should be treated as a container
  33. '  (organizationalUnit), a user (user), or simply ignored (group).
  34. Private Function IADType(iadVar As Object) As String
  35.     Dim varWork As Variant
  36.  
  37.     With iadVar
  38.         Call .GetInfo
  39.         For Each varWork In .Get("objectClass")
  40.             Select Case varWork
  41.             Case "user", "group", "organizationalUnit"
  42.                 IADType = varWork
  43.                 Exit For
  44.             End Select
  45.         Next varWork
  46.     End With
  47. End Function
The following procedure lists what it finds :
Expand|Select|Wrap|Line Numbers
  1. 'ShowIADs() shows all users, groups and containers of the AD from strRoot.
  2. Public Sub ShowIADs(Optional ByRef iadVar As Object, _
  3.                     Optional ByVal strRoot As String = "")
  4.     Dim iadWork As Object
  5.     Dim strWork As String
  6.  
  7.     If iadVar Is Nothing Then
  8.         strWork = "LDAP://" & _
  9.                   strRoot & _
  10.                   "OU=MyBusiness," & _
  11.                   GetObject("LDAP://RootDSE").Get("rootDomainNamingContext")
  12.         Set iadVar = GetObject(strWork)
  13.     End If
  14.     With iadVar
  15.         strWork = IADType(iadVar)
  16.         If strWork > "" Then
  17.             Debug.Print strWork & "," & _
  18.                         IIf(strWork = "user", .sAMAccountName, "") & "#" & _
  19.                         .distinguishedName & "~";
  20.         End If
  21.         Select Case strWork
  22.         Case "user"
  23.             Exit Sub
  24.         Case "organizationalUnit"
  25.             For Each iadWork In iadVar
  26.                 Call ShowIADs(iadWork)
  27.             Next iadWork
  28.         End Select
  29.     End With
  30. End Sub
I don't think there are any calls in here except to standard procedures. I think most of this is found in the VBA library.
Nov 9 '12 #3
ADezii
8,834 Expert 8TB
I have attached a Sample Database that should clearly demonstrate how to retrieve Information from Active Directory. It also display AD Variables that can be used in this same context.
Attached Files
File Type: zip Active Directory.zip (23.1 KB, 787 views)
Nov 12 '12 #4
anoble1
245 128KB
Very Nice, thanks guys
Nov 14 '12 #5
NeoPa
32,556 Expert Mod 16PB
No worries. I'm happy to share it.
Nov 15 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Victor Lokhmatov | last post by:
Hello Everyone, My company has asked me to put a company directory on our intranet site and I'm trying to use php to extract the users from our active directory server. I've got everything...
1
by: Henning Kristensen | last post by:
Hi I need a little help with some VB.Net code.. I am pulling my computer's GUID out using WMI Dim wmiObj As New System.Management.ManagementObjectSearcher("SELECT UUID FROM...
0
by: Henning Kristensen | last post by:
Hi I need a little help with some VB.Net code.. I am pulling my computer's GUID out using WMI Dim wmiObj As New System.Management.ManagementObjectSearcher("SELECT UUID FROM...
3
by: Ross Luker | last post by:
Hi, I've just started using ADSI to pull in info from our Active Directory tree into SQL Server 2000. I've made the link ok, and can pull in most fields (cn whenCreated etc) fine. However,...
0
by: Franklin Zabala | last post by:
Hello By any chance, anyone know how to delegate control of an object in active directory programmatically? particularly using C#... I've been pulling my hair for 4 days now and can't still find...
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
1
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
6
by: varkey.mathew | last post by:
Dear all, Bear with me, a poor newbie(atleast in AD).. I have to authenticate a user ID and password for a user as a valid Active Directory user or not. I have created the IsAuthenticated...
10
by: Hriday | last post by:
Hi there, Please help me..It is urgent This is Hriday, working on windows authentication with Active Directory... My requirment is when a user sends a request to my web Applicatoin I want to...
2
by: Joe Spears | last post by:
Hi Does anyone have any sample code on Pulling user data from Active Directory?? Thanks
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.