[DllImport("Netapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern int DsGetDcName
(
[MarshalAs(UnmanagedType.LPTStr)]
string ComputerName,
[MarshalAs(UnmanagedType.LPTStr)]
string DomainName,
[In] GuidClass DomainGuid,
[MarshalAs(UnmanagedType.LPTStr)]
string SiteName,
int Flags,
out IntPtr pDOMAIN_CONTROLLER_INFO
);
Declare Function DsGetDcName Lib "netapi32.dll" (TODO) As TODO
DOMAIN_CONTROLLER_INF0, GuidClass
Pointer to a PDOMAIN_CONTROLLER_INFO value that receives a pointer to a DOMAIN_CONTROLLER_INFO structure that contains data about the domain controller selected. This structure is allocated by DsGetDcName. The caller must free the structure using the NetApiBufferFree function when it is no longer required.
Please add some!
private DOMAIN_CONTROLLER_INFO GetDomainInfo()
{
DOMAIN_CONTROLLER_INFO domainInfo;
IntPtr pDCI = IntPtr.Zero;
try
{
int val = DsGetDcName(null, null, null, null, 0, out pDCI);
//check return value for error
if(ERROR_SUCCESS == val)
{
domainInfo = (DOMAIN_CONTROLLER_INFO)Marshal.PtrToStructure(pDCI, typeof(DOMAIN_CONTROLLER_INFO));
}
else
{
throw new Win32Exception(val);
}
}
finally
{
NetApiBufferFree(pDCI);
}
return domainInfo;
}
TODO