Platform SDK: Network Management

NetGetDCName

The NetGetDCName function returns the name of the primary domain controller (PDC). It does not return the name of the backup domain controller (BDC) for the specified domain. Also, you cannot remote this function to a non-PDC server.

Windows 2000: Win32-based applications that support DNS-style names should call the DsGetDcName function. Domain controllers in a Windows 2000 environment have a multi-master directory replication relationship. Therefore, it may be advantageous for your application to use a DC that is not the PDC. You can call the DsGetDcName function to locate any DC in the domain; NetGetDCName returns only the name of the PDC.

Security Requirements

No special group membership is required to successfully execute the NetGetDCName function.

NET_API_STATUS NetGetDCName(
  LPCWSTR servername,  
  LPCWSTR domainname,  
  LPBYTE *bufptr       
);

Parameters

servername
[in] Pointer to a constant Unicode string specifying the name of the remote server on which the function is to execute. The string must begin with \\. If this parameter is NULL, the local computer is used.
domainname
[in] Pointer to a constant Unicode string specifying the name of the domain. The domain name must be a NetBIOS domain name (for example, microsoft). NetGetDCName does not support DNS-style names (for example, microsoft.com). If this parameter is NULL, the function returns the name of the domain controller for the primary domain.
bufptr
[out] Pointer to an allocated buffer that receives a Unicode string which specifies the server name of the PDC of the domain. The server name is prefixed by \\. This buffer is allocated by the system and must be freed using the NetApiBufferFree function.

Return Values

If the function succeeds, the return value is NERR_Success.

If the function fails, the return value can be one of the following error codes.

Value Meaning
NERR_DCNotFound Could not find the domain controller for the domain.
ERROR_INVALID_NAME The name could not be found.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Unsupported.
  Header: Declared in Lmaccess.h; include Lm.h.
  Library: Use Netapi32.lib.

See Also

Network Management Overview, Network Management Functions, Get Functions, DsGetDcName, NetGetAnyDCName