Platform SDK: Network Management

NetGetAnyDCName

The NetGetAnyDCName function returns the name of any domain controller (DC) for a domain that is directly trusted by the specified server.

Windows 2000: Win32-based applications that support DNS-style names should call the DsGetDcName function. DsGetDcName can locate any DC in any domain, whether or not the domain is directly trusted by the specified server.

Security Requirements

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

NET_API_STATUS NetGetAnyDCName(
  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. For more information, see the following Remarks section.
domainname
[in] Pointer to a constant Unicode string specifying the name of the domain. If this parameter is NULL, the name of the domain controller for the primary domain is used. For more information, see the following Remarks section.
bufptr
[out] Pointer to an allocated buffer that receives a Unicode string specifying the server name of a domain controller for 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
ERROR_NO_LOGON_SERVERS No domain controllers could be found.
ERROR_NO_SUCH_DOMAIN The specified domain is not a trusted domain.
ERROR_NO_TRUST_LSA_SECRET The client side of the trust relationship is broken.
ERROR_NO_TRUST_SAM_ACCOUNT The server side of the trust relationship is broken or the password is broken.
ERROR_DOMAIN_TRUST_INCONSISTENT The server that responded is not a proper domain controller of the specified domain.

Remarks

If servername specifies a stand-alone Windows NT/Windows 2000 workstation or a stand-alone server, no domainname is valid.

If servername specifies a Windows NT/Windows 2000 workstation that is a member of a domain, or a Windows NT/Windows 2000 server that is a member of a domain, the domainname must be in the same domain as servername.

If servername specifies a domain controller, the domainname must be one of the domains trusted by the domain for which the server is a controller. The domain controller that this call finds has been operational at least once during this call.

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, NetGetDCName