Directory Services


The DsRemoveDsServer function removes all traces of a directory service agent (DSA) from the global area of the directory service.

DWORD DsRemoveDsServer(
  LPTSTR ServerDN,
  LPTSTR DomainDN,
  BOOL* fLastDcInDomain,
  BOOL fCommit


[in] Bind handle to the directory service. This handle is returned by a call to the DsBind or DsBindWithCred functions.
[in] Pointer to a null-terminated string that specifies the fully-qualified distinguished name of the domain controller to remove. For example, if the name of the domain controller to be removed is TestDC, the site name is Default-First-Site-Name, and the domain is, the fully-qualified distinguished name is as follows.
[in, optional] Pointer to a null-terminated string that specifies a domain hosted by ServerDN. If this parameter is NULL, no verification is performed to ensure that ServerDN is the last domain controller in DomainDN.
[out, optional] Pointer to a Boolean value that receives TRUE if ServerDN is the last DC in DomainDN or FALSE otherwise. This parameter receives FALSE if DomainDN is NULL.
[in] Contains a Boolean value that specifies if the domain controller should actually be removed. If this parameter is non-zero, ServerDN is removed. If this parameter is zero, the existence of ServerDN is checked and fLastDcInDomain is written, but the domain controller is not removed.

Return Values

Returns ERROR_SUCCESS if successful or a Win32 or RPC error code if unsuccessful. Possible error codes include the following.
Return Code Description
ERROR_ACCESS_DENIED The caller does not have permissions to delete ServerDN.
ERROR_DS_BAD_NAME_SYNTAX Returned when fCommit is non-zero and the syntax of ServerDN is invalid.
ERROR_DS_CANT_DELETE_DSA_OBJ The bind handle supplied in hDs is currently bound to ServerDN.
ERROR_DS_NO_CROSSREF_FOR_NC Cannot find a cross reference object for DomainDN.
ERROR_INVALID_PARAMETER One or more parameters are invalid.
RPC_S_CANNOT_SUPPORT The DsRemoveDsServer function is not supported.
RPC_S_INVALID_VERS_OPTION A versioning error occurred.


Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension on Windows NT 4.0 SP6a and Windows 95/98/Me.
Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000/XP.
Header: Declared in Ntdsapi.h.
Library: Use Ntdsapi.lib.

See Also

DsBind, DsBindWithCred, DsRemoveDsDomain, Domain Controller and Replication Management Functions