Directory Services

IADsADSystemInfo::GetDCSiteName

The IADsADSystemInfo::GetDCSiteName method retrieves the name of the Active Directory site that contains the local computer.

HRESULT GetDCSiteName( 
  BSTR* pbstrSiteName,
  BSTR* szServer
);

Parameters

pbstrSiteName
[out] Name of the Active Directory site.
szServer
[in] DNS name of the service server.

Return Values

This method supports the standard HRESULT return values. For more information, see ADSI Error Codes.

Remarks

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.

Example Code [C++]

The following C++ code example 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);
 
	IADsADSystemInfo *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;
}

Example Code [Visual Basic]

The following Visual Basic code example retrieves the name of the Active Directory domain controller site.

Dim sys As New ADSystemInfo
Debug.Print "Domain Controller site: " & sys.GetDCSiteName

Example Code [VBScript]

The following VBScript/ASP code example retrieves the name of the Active Directory domain controller site.

<%
Dim sys
Set sys = Server.CreateObject("ADSystemInfo")
Response.Write "Domain Controller: " & sys.GetDCSiteName
%>

Requirements

Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Header: Declared in Iads.h.

See Also

IADsADSystemInfo, ADSI Error Codes, Active Directory Core Concepts