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.
Applications that support DNS-style names should call the DsGetDcName function. Domain controllers in this type of 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.
NET_API_STATUS NET_API_FUNCTION NetGetDCName( IN LPCWSTR servername OPTIONAL, IN LPCWSTR domainname OPTIONAL, LPBYTE *bufptr );
A pointer to an allocated buffer that receives a string that specifies the server name of the PDC of the domain. The server name is returned as Unicode string prefixed by \. This buffer is allocated by the system and must be freed using the NetApiBufferFree function. For more information, see Network Management Function Buffers and Network Management Function Buffer Lengths.
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.
||Could not find the domain controller for the domain specified in the domainname parameter.|
||The network path was not found. This error is returned if the computer specified in the servername parameter could not be found.|
||The name syntax is incorrect. This error is returned if the name specified in the servername parameter contains illegal characters.|
||The request is not supported.|
No special group membership is required to successfully execute the NetGetDCName function.
The following code sample demonstrates how to retrieve the primary domain controller using the
NetGetDCName function. The sample calls NetGetDCName specifying the servername and domainname parameters. If the call succeeds, the code prints information out the name of the primary domain controller. Finally, the sample frees the memory allocated for the buffer where the domain controller name was returned.
#ifndef UNICODE #define UNICODE #endif
|Windows version||Windows 2000 Professional [desktop apps only] Windows 2000 Server [desktop apps only]|
|Header||lmaccess.h (include Lm.h)|