473,378 Members | 1,446 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,378 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 2140
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...
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.