SIGN UP MEMBER LOGIN:    
ARTICLE

Active Directory Sample I

Posted by John O Donnell Articles | Active Directory C# August 23, 2001
This sample shows how to access Active Directory information in a Windows 2000 domain.
Reader Level:
Download Files:
 

This sample shows how to access Active Directory information in a Windows 2000 domain.

My test network consists of a Windows 2000 domain controller and a Windows 2000 server. When you install a Windows 2000 domain controller and are creating a new domain you install both the active directory and DNS which the active directory uses. The Active Directory in Windows 2000 allows you to store information about servers, printers, users etc.

So finally I thought yeah very nice, wonder if I can run code from my server to access the directory information. Below is the code which lists all the entries in my small active Directory. Note my domain is called Microsoft for testing purposes.

Source Code:

// Active Directory Sample 1
// Lists all entries in the Active Directory for Domain microsoft.
using
System;
using
System.DirectoryServices;
namespace
ActiveDirectory
{
///
<summary>
///
Summary description for Class1.
/// </summary>

class
Class1
{
static void Main (string
[] args)
{
//Note : microsoft is the name of my domain for testing purposes.
DirectoryEntry entry = new
DirectoryEntry(LDAP://microsoft);
System.DirectoryServices.DirectorySearcher mySearcher =
new
System.DirectoryServices.DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=*)");
Console.WriteLine("Active Directory Information");
Console.WriteLine("===========================================");
foreach(System.DirectoryServices.SearchResult resEnt in
mySearcher.FindAll())
{
Console.WriteLine( resEnt.GetDirectoryEntry().Name.ToString() );
Console.WriteLine( resEnt.GetDirectoryEntry().Path.ToString() );
Console.WriteLine( resEnt.GetDirectoryEntry().NativeGuid.ToString() );
Console.WriteLine("===========================================");
}
}
}
}

Login to add your contents and source code to this article
share this article :
post comment
 

i am trying to add user accounts in active directory but i am not able to write a code for the same, i have following data that needs to be added in the user account properties. First Name, Last Name, Lan ID, Employee ID (Should be entered in the description field in AD), Change Password (Yes check Mark which is always enabled), Home Drive (should display the path of the drive + lan id), Department (considering 3 departments). now i am not able to understand where to put or write the code (in seperate file or the same details.aspx file) and when to call which function to get the user accounts created. please help me writing this code so that i can learn some advanced things in asp.net. Thanks in advance

Posted by hitender yadav Oct 22, 2007
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Become a Sponsor