[DllImport("Netapi32.dll")]
static extern NetApiStatus NetApiBufferFree(IntPtr Buffer);
[DllImport("Netapi32.dll", CharSet=CharSet.Unicode)]
static extern NetApiStatus NetGetDCName(string serverName, string domainName, out IntPtr buffer);
(TODO)
public enum NetApiStatus
{
Success = 0,
DCNotFound = 2453
}
Do you know one? Please contribute it!
None.
Please add some!
public static string GetDCName()
{
IntPtr domainInfo = IntPtr.Zero;
string dcName = String.Empty;
try
{
NetApiStatus result = NetGetDCName(null, null, out domainInfo);
if (result == NetApiStatus.Success)
{
dcName = Marshal.PtrToStringAuto(domainInfo);
}
}
finally
{
NetApiBufferFree(domainInfo);
}
return dcName;
}