| Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsADSystemInfo::GetDCSiteName method retrieves the name of the Active Directory™ domain controller site that the Windows® 2000 system belongs to.
HRESULT IADsADSystemInfo::GetDCSiteName( BSTR *pbstrSiteName );
This method supports the standard HRESULT return values. For more information, see ADSI Error Codes.
An Active Directory site is one or more well-connected TCP/IP subnets holding Active Directory domain controllers. For more information, see Active Directory Core Concepts.
The following C++ code snippet retrieves the Active Directory site name. 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->GetDCSiteName(&bstr);
if (SUCCEEDED(hr)) {
printf("Domain controller site: %S\n", bstr);
SysFreeString(bstr);
}
if(pSys) {
pSys->Release();
}
CoUninitialize();
return 0;
}
The following Visual Basic® code snippet retrieves the name of the Active Directory domain controller site.
Dim sys As New ADSystemInfo Debug.Print "Domain Controller site: " & sys.GetDCSiteName
The following VBScript/ASP code snippet retrieves the name of the Active Directory domain controller site.
<%
Dim sys
Set sys = Server.CreateObject("ADSystemInfo")
Response.Write "Domain Controller: " & sys.GetDCSiteName
%>
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Unsupported.
Header: Declared in Iads.h.
IADsADSystemInfo, ADSI Error Codes, Active Directory Core Concepts