473,698 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Querying Active Directory for a specific user

Seth Schrock
2,965 Recognized Expert Specialist
I have found the following thread which ADezii solved very nicely: ...Grab information from AD.... However, this just pulls for the current user. I want to be able to specify the user so that I can get their email address. From research that I have done online (ADSI Active Directory), you must use LDAP and not WinNT to be able to pull the EmailAddress property of the user. Again from looking online, it seems that I need to know the OU where the user is located to be able to do this. The problem is that our users are arranged through many different OUs and I can't predict where via code.

What I'm trying to do is get the email addresses for everyone in a specific security group. I had managed to get several pieces of information using the following code.
Expand|Select|Wrap|Line Numbers
  1. Public Sub UsersInGroup(GroupName As String)
  2. Dim adGroup As ActiveDs.IADsGroup
  3. Dim adMembers As IADsMembers
  4. Dim adMember As IADs
  5. Dim adNTUser As IADsUser
  6.  
  7. Set adGroup = GetObject("WinNT://MyDomain/" & GroupName)
  8. Set adMembers = adGroup.Members
  9.  
  10. For Each adMember In adMembers
  11.  
  12.     Set adNTUser = GetObject("WinNT://MyDomain/" & adMember.Name & ",user")
  13.     Debug.Print adMember.Name, adNTUser.FullName, adNTUser.IsAccountLocked, adNTUser.PasswordExpirationDate, adNTUser.EmailAddress
  14.  
  15. Next
  16.  
  17. End Sub
  18.  
Everything in this works except for the adNTUser.EmailA ddress at the end of the Debug.Print line. So I just need to replace the WinNT string with an LDAP string that allows me to search for the user by username. I had tried
Expand|Select|Wrap|Line Numbers
  1. "LDAP://CN=" & adNTUser.FullName & ",CN=Users,DC=MyDomain,DC=com"
but I get an error saying "There is no such object on the server". I don't know much about LDAP and I have no clue what else to try.
Oct 28 '14
10 12940
Rabbit
12,516 Recognized Expert Moderator MVP
If you are referring to Seth's code, I'm not sure which reference he's using to get access to the ActiveDs objects. However, if you go to my original VBS code, with minor modifications that should work in VBA without needing an additional reference.
Mar 25 '19 #11

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

Similar topics

0
1015
by: Trey Mitchell | last post by:
I have built a single class in vb.Net to handle all active directory authentication needed in my web app. People can sign into the website with no problem. There is also a second form of authentication that users can have to access the website. When they use the second form (uses db backend), I see if I know their AD username (stored in db). If I don't know AD username, I put up a form asking for credentials. When you put in your...
0
995
by: Brian Mitchell | last post by:
Is there any way to return active directory objects from the object's guid? My basic problem is that I don't know the appropriate search filters. Does anyone know of any sites that list them? (like sn searches for surname) Thanks in advance!!
0
989
by: Gary | last post by:
I'm creating an Infopath form and I need to query Active Directory to obtain some data. Here is the code I'm using (obtained from sample code from MSDN) Private Shared domainADsPath As String = "LDAP://xxx.com" Private Shared username As String = "gary" Private Shared password As String = "password" Private Shared schemaClassNameToSearch As String = "user" Sub Lookup Dim strUserName as String
0
1168
by: hellosibba | last post by:
i am trying to enumerate and query the organization Domain controller to get all the domains and its corresponding users in it. i also want to query the user's information like full name, designation, contact number.. whatever is being assigned for that user in the domain. i am using vb2005 and the following namespace Imports System.DirectoryServices Imports System.DirectoryServices.ActiveDirectory also referred the following url ...
4
10914
by: cpajoe2001 | last post by:
I am not sure if this is the proper place to put this thread but I have run into a road block. I am writing a web app that will create groups in Active Directory then add users to those groups. I have it creating the groups just fine however when i go to add a user i get. The requested operation did not satisfy one or more constraints associated with the class of the object. (Exception from HRESULT: 0x80072014) And I can not find any help on...
3
2813
by: Brian McCullough | last post by:
Hello, I am trying to query ADAM using the ActiveDirectoryMembershipProvider in my ASP.NET 2.0 application, but have been unsuccessful. I have followed the steps in these blog posts, but still am not able to query ADAM. Every time I make a call to login, using the Membership.ValidateUser method, I keep getting a false value. I have tried many different variations of the username including "localhost\myuseraccount",...
0
1094
by: gdltec | last post by:
I have an ASP page that needs to be populated with employee data from Active Directory (i.e. Name, email, manager, etc), can anyone help me out on how to acomplish this? I just need to know how to query AD from classic ASP. thanks,
0
4156
by: justintaitt | last post by:
Hi, I am new to active directory and am trying to query it for the user name and ID of members of a group to populate a drop down list in the form: firstname lastname (userID) When I run the page which calls this function through visual studio it works fine and the drop down list is populated. However when I run the page over the intranet I get this error. Unknown error (0x8000500c) Description: An unhandled exception occurred during the...
4
5251
by: jllg2000 | last post by:
I got this query: CREATE VIEW viewADContacts AS SELECT , SN , ST State FROM OPENQUERY( ADSI2, 'SELECT Name, SN, ST FROM ''LDAP://presidencia.local/CN=Users, DC=domainname,DC=local''') GO
0
1075
by: VBDevo | last post by:
Hello, Can anyone help me in this please I'm trying to restore an Active Directory deleted user, I found the code only in c++ in the MSDN, and it uses the DLL : wldap32.dll , which is under system32 in windows , but when I try to add reference it gives me an error that the assembly is not valid. would you tell me how should I use it , or how should I use the LDAPControl or how can we restore an AD object in vb.net please Thank you
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7729
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.