| Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsADSystemInfo::GetAnyDCName method retrieves the name of an Active Directory domain controller in the format of "serverName.DNSDomainName".
HRESULT IADsADSystemInfo::GetAnyDCName( BSTR *pbstDCName );
This method supports the standard HRESULT return values. For more information, see ADSI Error Codes.
The following C++ code snippet retrieves the Windows® 2000 system information. For brevity, error checking is omitted.
#include <activeds.h>
#include <stdio.h>
int main()
{
HRESULT hr;
hr = CoInitialize(NULL);
IADsWinNTSystemInfo *pSys;
hr = CoCreateInstance(CLSID_ADSystemInfo,
NULL,
CLSCTX_INPROC_SERVER,
IID_IADsADSystemInfo,
(void**)&pSys);
BSTR bstr;
hr = pSys->GetAnyDCName(&bstr);
if (SUCCEEDED(hr)) {
printf("Domain controller: %S\n", bstr);
SysFreeString(bstr);
}
if(pSys) {
pSys->Release();
}
CoUninitialize();
return 0;
}
The following Visual Basic® code snippet uses the IADsADSystemInfo::GetAnyDCName method to retrieve the name of the Active Directory domain controller.
Dim sys As New ADSystemInfo Debug.Print "Domain Controller: " & sys.GetAnyDCName
The following VBScript/ASP code snippet uses the IADsADSystemInfo::GetAnyDCName method to retrieve the name of the Active Directory domain controller.
<%
Dim sys
Set sys = Server.CreateObject("ADSystemInfo")
Response.Write "Domain Controller: " & sys.GetAnyDCName
%>
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Unsupported.
Header: Declared in Iads.h.