home *** CD-ROM | disk | FTP | other *** search
Wrap
<!-- #include virtual="/quickstart/howto/include/header.inc" --> <h4>How Do I...Access Active Directory?</h4> <div class="indent" style="width:660"> <p class="MsoNormal"><font face="Tahoma" size="1">Active Directory Service Interfaces (ADSI) accesses the capabilities of directory services from different network providers in a distributed computing environment, to present a single set of directory service interfaces for managing network resources. Administrators and developers can use ADSI services to enumerate and manage the resources in a directory service, no matter which network environment contains the resource. Use Active Directory to perform common administrative tasks, such as locating resources throughout the distributed computing environment.</font></p> <p class="MsoNormal"><span style="mso-fareast-font-family: Times New Roman; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"><font size="1" face="Tahoma">This sample illustrates how to locate resources in the Active Directory. </font></span><span style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">It's a small console application that can be run from a command prompt. The application takes one command line argument. The first argument has to be a valid path to an active directory entry.<O:P> </O:P> </span></p> <p class="Text"><span style="FONT-SIZE: 8pt; FONT-FAMILY: Tahoma; mso-bidi-font-size: 10.0pt">Try running the following command substituting the path for a valid Active Directory path for your particular network:<O:P> </O:P> </span></p> <p class="MsoNormal" style="MARGIN-LEFT: 0.5in"><font face="Courier New" size="2"><span style="COLOR: blue; mso-bidi-font-size: 12.0pt">> ADRead.exe "LDAP://DC=Microsoft,DC=COM"</span></font></p> <p class="MsoNormal"><font face="Tahoma" size="1">In its simplest form, reading from the Active Directory involves:<o:p> </o:p> </font></p> <font face="Tahoma" size="1">1. Creating a new DirectoryEntry:</font> <blockquote> <p class="MsoNormal"><span style="mso-bidi-font-size: 12.0pt"><font face="Courier New" size="2" color="#0000FF">DirectoryEntry entry=new DirectoryEntry(path);</font><font face="Tahoma" size="1"><o:p> </o:p> </font></span></p> </blockquote> <p class="MsoNormal"><font face="Tahoma" size="1"> 2. Reading the information from the Active Directory and printing it to the screen:</font></p> <blockquote> <p class="MsoNormal" style="word-spacing: 0; margin-top: 0; margin-bottom: 0"><span style="mso-bidi-font-size: 12.0pt"><font face="Courier New" size="2" color="#0000FF">foreach(DirectoryEntryProperty objP in entry.Properties){<o:p> </o:p> </font></span></p> <p class="MsoNormal" style="word-spacing: 0; margin-top: 0; margin-bottom: 0"><span style="mso-bidi-font-size: 12.0pt"><font face="Courier New" size="2" color="#0000FF"> Console.Write(objP.Name + " = ");<o:p> </o:p> </font></span></p> <p class="MsoNormal" style="word-spacing: 0; margin-top: 0; margin-bottom: 0"><span style="mso-bidi-font-size: 12.0pt"><font face="Courier New" size="2" color="#0000FF"> foreach(Object objValue in objP.Values) <o:p> </o:p> </font></span></p> <p class="MsoNormal" style="word-spacing: 0; margin-top: 0; margin-bottom: 0"> <font face="Courier New" size="2" color="#0000FF"><span style="mso-bidi-font-size: 12.0pt"> </span></font> <font face="Courier New" size="2" color="#0000FF"><span style="mso-bidi-font-size: 12.0pt">Console.Write(objValue + ", ");</span></font></p> <p class="MsoNormal" style="word-spacing: 0; margin-top: 0; margin-bottom: 0"><font face="Courier New" size="2" color="#0000FF"><span style="mso-bidi-font-size: 12.0pt">}</span></font><span style="mso-bidi-font-size: 12.0pt"><font face="Courier New" size="2" color="#0000FF"><o:p> </o:p> </font></span></p> </blockquote> </div> <h4>Example</h4> <p> <div class="indent"> <a target="_blank" href="/quickstart/howto/samples/Services/DirectoryServices/ADRead"> <img style="border-color:black" border=1 src="/quickstart/images/genicon.gif"><br> </a> <div class="caption">ADRead.exe</div><br> [<a target="_blank" href="/quickstart/howto/samples/Services/DirectoryServices/ADRead">View Sample</a>] | [<a target="_blank" href="/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/DirectoryServices/ADRead/ADRead.src">View Source</a>]<p> </div> <h4>Source Code</h4> <div class="code"> <xmp> <!-- #include virtual="/quickstart/howto/samples/Services/DirectoryServices/ADRead/ADRead.cs" --> </xmp> </div> <!-- #include virtual="/quickstart/howto/include/footer.inc" -->