Use online neighbors in C #

xiaoxiao2021-03-06  51

The System.DirectoryServices.DirectoryEntry component provides access to Active Directory is what you want, I send an example of using the DirectoryEntry component that provides the Path property, according to the document, this property specifies the object name used to access the object in the directory service. The format is as follows: protocol: // servername: port number / distinguished name This statement defines the protocol that will be used, such as LDAP: (Lightweight Directory Access Protocol) IIS: (Provides IIS metadata to read and configure Internet Infomation) Server) WINNT: (Provides access to Windows NT Domain) NDS: (Provides access to Novell Directory Service), etc. (Details Clear reference MSDN). According to this, we construct a DirectoryEntry instance, set its PATH to "Winnt:" to discover all domains (and working groups) on the network by enumerating the enumerations of it. In this way, the sub-items of the found domains (and the working group) can be enumerated, and all the computers on the network can be found. One of the console applets demonstrate this. using System; using System.DirectoryServices; class TempClass {static void Main () {EnumComputers ();} static void EnumComputers () {using (DirectoryEntry root = new DirectoryEntry ( "WinNT:")) {foreach (DirectoryEntry domain in root. Children) {Console.Writeline ("Domain | Workgroup: / T" Domain.Name); Foreach (DirectoryEntry Computer In Domain.children) {Console.WriteLine ("Computer: / T" Computer.name);}}} } -------------------------------------------------------------------------------------------- -------------------------------- Improved Windows Forms scheme above the code in the code in two nesting foreach cycles look Not too good, and the display effect of the console is not so beautiful. Below, I will change the code and transplant it to WinForm. Create a Windows Application [C #], add a TreeView on the Form, named TreeView1.

转载请注明原文地址:https://www.9cbs.com/read-116672.html

New Post(0)