473,473 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Accessing Active Directory

Hi
I want to access via VB.Net the active directory
I want to list all the users and groups in AD and, if it's possible, also the exchange mailbox of each users..

Anyone can help me? Please...

Michele
Jul 21 '05 #1
6 2147
Check out the System.DirectoryServices Namespace

"MIchele" <mm******@omniway.sm> wrote in message
news:BD**********************************@microsof t.com...
Hi,
I want to access via VB.Net the active directory.
I want to list all the users and groups in AD and, if it's possible, also the exchange mailbox of each users...
Anyone can help me? Please....

Michele

Jul 21 '05 #2
Check out the System.DirectoryServices Namespace

"MIchele" <mm******@omniway.sm> wrote in message
news:BD**********************************@microsof t.com...
Hi,
I want to access via VB.Net the active directory.
I want to list all the users and groups in AD and, if it's possible, also the exchange mailbox of each users...
Anyone can help me? Please....

Michele

Jul 21 '05 #3
>I want to access via VB.Net the active directory.
I want to list all the users and groups in AD and, if it's possible, also the exchange mailbox of each users...


All users across all OU's in your AD ?? There could be many....

THis is C# - should be easy to convert to VB.NET - you'll need to use
the DirectorySearcher class:

DirectorySearcher oSrch = new DirectorySearcher("");

oSrch.Filter = "(&(objectClass=user)(objectCategory=user))";
oSrch.SearchScope = SearchScope.Subtree;

oSrch.PropertiesToLoad.Add("givenName");
oSrch.PropertiesToLoad.Add("sn");
oSrch.PropertiesToLoad.Add("mail");

foreach(SearchResult oRes in oSrch.FindAll())
{
Console.WriteLine("User: " +
oRes.Properties["givenName"].Value.ToString() + " " +
oRes.Properties["sn"].Value.ToString() + " / E-Mail: " +
oRes.Properties["mail"].Value.ToString();
}

It searches the directory, load the "givenName" and "sn" (Surname") as
well as "mail" (e-mail address) properties for the search results, and
loops through the results.

For groups, you'll just need to adjust the filter accordingly.

Marc

Jul 21 '05 #4
>I want to access via VB.Net the active directory.
I want to list all the users and groups in AD and, if it's possible, also the exchange mailbox of each users...


All users across all OU's in your AD ?? There could be many....

THis is C# - should be easy to convert to VB.NET - you'll need to use
the DirectorySearcher class:

DirectorySearcher oSrch = new DirectorySearcher("");

oSrch.Filter = "(&(objectClass=user)(objectCategory=user))";
oSrch.SearchScope = SearchScope.Subtree;

oSrch.PropertiesToLoad.Add("givenName");
oSrch.PropertiesToLoad.Add("sn");
oSrch.PropertiesToLoad.Add("mail");

foreach(SearchResult oRes in oSrch.FindAll())
{
Console.WriteLine("User: " +
oRes.Properties["givenName"].Value.ToString() + " " +
oRes.Properties["sn"].Value.ToString() + " / E-Mail: " +
oRes.Properties["mail"].Value.ToString();
}

It searches the directory, load the "givenName" and "sn" (Surname") as
well as "mail" (e-mail address) properties for the search results, and
loops through the results.

For groups, you'll just need to adjust the filter accordingly.

Marc

Jul 21 '05 #5
Here is your starting point:

Dim enTry As DirectoryEntry = New DirectoryEntry(LDAP://<DomainNameHere>)
Console.WriteLine("Active Directory Information")
Console.WriteLine("=============================== ============")
For Each resEnt As DirectoryEntry In enTry.Children
If (resEnt.SchemaClassName().Equals("organizationalUn it")) Then
Console.WriteLine(resEnt.Name.ToString())
'Console.WriteLine(resEnt.GetDirectoryEntry().Path .ToString())
'Console.WriteLine(resEnt.GetDirectoryEntry().Nati veGuid.ToString())
Console.WriteLine("=============================== ============")
Else
Debug.WriteLine(resEnt.SchemaClassName().ToString( ))
End If
Next

Don't forget a reference to the System.DirectoryServices namespace, and be sure to use your domain name in the code.

-Enjoy!!

-Evan
"MIchele" <mm******@omniway.sm> wrote in message news:BD**********************************@microsof t.com...
Hi,
I want to access via VB.Net the active directory.
I want to list all the users and groups in AD and, if it's possible, also the exchange mailbox of each users...

Anyone can help me? Please....

Michele

Jul 21 '05 #6
Here is your starting point:

Dim enTry As DirectoryEntry = New DirectoryEntry(LDAP://<DomainNameHere>)
Console.WriteLine("Active Directory Information")
Console.WriteLine("=============================== ============")
For Each resEnt As DirectoryEntry In enTry.Children
If (resEnt.SchemaClassName().Equals("organizationalUn it")) Then
Console.WriteLine(resEnt.Name.ToString())
'Console.WriteLine(resEnt.GetDirectoryEntry().Path .ToString())
'Console.WriteLine(resEnt.GetDirectoryEntry().Nati veGuid.ToString())
Console.WriteLine("=============================== ============")
Else
Debug.WriteLine(resEnt.SchemaClassName().ToString( ))
End If
Next

Don't forget a reference to the System.DirectoryServices namespace, and be sure to use your domain name in the code.

-Enjoy!!

-Evan
"MIchele" <mm******@omniway.sm> wrote in message news:BD**********************************@microsof t.com...
Hi,
I want to access via VB.Net the active directory.
I want to list all the users and groups in AD and, if it's possible, also the exchange mailbox of each users...

Anyone can help me? Please....

Michele

Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Brandon Arnold | last post by:
Hello All, I have a linked ADSI Server to our company Active Directory and everything is fine. I'm running queries and such using LDAP. BUT how can I aquire a list of attributes for the classes...
9
by: Mario Rodriguez | last post by:
Hi people. I have a problem adding users to Win2003 active directory programatically. When I execute my app throws the following exception: .................The specified directory service...
1
by: Toufani | last post by:
Hi everybody, I want to retrieve information about objects in active directory windows 2000 and their properties. I got some codes that don't work absolutely. for example I can't retrieve users...
1
by: unerwartet | last post by:
Hi, I want to access the high-watermark-vector of a specific domain controller in the active directory from c#. But I do not know how to achieve this. I tried it with: ...
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...
8
by: thomson | last post by:
Hi, Is it possible to access the user information from a Web Application, Iam not able to use System.DirectoryServices from my code behind.---using System.DirectoryServices What am i missing? ...
2
by: Conversão .cs em .dll | last post by:
I'm having a problem accessing Active Directory, the problem is that I need to access the passwords of the user to validate a login that i'm doing. I have access for the usernames but not to there...
2
by: =?Utf-8?B?SklNLkgu?= | last post by:
Accessing AD in ASP.Net 1. It sees I can I access Active Directory catalog from asp.net, is the version of AD important for this? 2. Do I need to have a domain user for that or IIS will be...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
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.