473,395 Members | 1,488 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,395 software developers and data experts.

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 2143
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
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...

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.