DsGetDcName function

  • Thread starter Thread starter Guest
  • Start date Start date
Mike said:
Does anyone have an example of how to call this API within C#?

You better stay away from calling native API's when the FCL offers an
alternative, take a look at the System.Management or the
System.DirectoryServices classes.

Here is a sample using the former, illustrating how to get at the DC
properties:

using System;
using System.Management;
class App {
public static void Main() {
SelectQuery query = new SelectQuery("select * from win32_NTDomain where
description='celeb'");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject mo in searcher.Get()) {
// display some properties , check the Platform SDK docs (WMI) for more
info
Console.WriteLine("Domain Name: {0} - DC Name{1} - DC Address{2}
",mo["DomainName"],mo["DomainControllerName"],mo["DomainControllerAddress"]);
}
}
}

Willy.
 
Back
Top