how to list network computer name, Ip in C#
-
i want to list all Computer Name, and Ip Address for the Domin "WLINKTECH". i use the following code but get an error like this, so plz help me about the problem. -------------------- using System; using System.DirectoryServices; namespace IPAddressof_RemoteComputer { public class Class1 { public Class1() { // // TODO: Add constructor logic here // } public void getIpCName() { DirectoryEntry entry = new DirectoryEntry("LDAP://wlinktech"); DirectorySearcher mySearcher = new DirectorySearcher(entry); mySearcher.Filter = ("(objectClass=computer)"); Console.WriteLine("Listing of computers in the Active Directory"); Console.WriteLine("============================================"); foreach(SearchResult resEnt in mySearcher.FindAll()) { Console.WriteLine(resEnt.GetDirectoryEntry().Name.ToString()); } Console.WriteLine("=========== End of Listing ============="); } } } --------------- Error like this ------------------ An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in system.directoryservices.dll Additional information: The server is not operational Sanjit.rajbanshi@wlinktech.com
-
i want to list all Computer Name, and Ip Address for the Domin "WLINKTECH". i use the following code but get an error like this, so plz help me about the problem. -------------------- using System; using System.DirectoryServices; namespace IPAddressof_RemoteComputer { public class Class1 { public Class1() { // // TODO: Add constructor logic here // } public void getIpCName() { DirectoryEntry entry = new DirectoryEntry("LDAP://wlinktech"); DirectorySearcher mySearcher = new DirectorySearcher(entry); mySearcher.Filter = ("(objectClass=computer)"); Console.WriteLine("Listing of computers in the Active Directory"); Console.WriteLine("============================================"); foreach(SearchResult resEnt in mySearcher.FindAll()) { Console.WriteLine(resEnt.GetDirectoryEntry().Name.ToString()); } Console.WriteLine("=========== End of Listing ============="); } } } --------------- Error like this ------------------ An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in system.directoryservices.dll Additional information: The server is not operational Sanjit.rajbanshi@wlinktech.com
Hi Sanjit.rajbanshi, I have tested your code in Window Application (C#) after changing my AD name (sync.net). It's working fine. I have no problem with it. maybe. you are getting this error cuz you dont have the permission or you might put wrong AD name. If your application is web application then you need to impersonate ur account.
Thanks and Regards, Michael Sync Blog: http://michaelsync.net