Platform SDK: Network Management |
The NetJoinDomain function joins a computer to a workgroup or domain.
Joining (and unjoining) a computer to a domain or workgroup can be performed only by a member of the Administrators local group on the target computer. Note that the domain administrator can set additional requirements for joining the domain using delegation and assignment of privileges.
If you call the NetJoinDomain function remotely, you must supply credentials because you cannot delegate credentials under these circumstances.
NET_API_STATUS NetJoinDomain( LPCWSTR lpServer, LPCWSTR lpDomain, LPCWSTR lpAccountOU, LPCWSTR lpAccount, LPCWSTR lpPassword, DWORD fJoinOptions );
Optionally, you can specify the preferred domain controller to perform the join operation. In this instance, the string must be of the form DomainName\MachineName, where DomainName is the name of the domain to join, and MachineName is the name of the domain controller to perform the join.
Value | Meaning |
---|---|
NETSETUP_JOIN_DOMAIN | Joins the computer to a domain. If this value is not specified, joins the computer to a workgroup. |
NETSETUP_ACCT_CREATE | Creates the account on the domain. |
NETSETUP_WIN9X_UPGRADE | The join operation is occurring as part of an upgrade of Windows 95/98 to Windows NT/Windows 2000. |
NETSETUP_DOMAIN_JOIN_IF_JOINED | Allows a join to a new domain even if the computer is already joined to a domain. |
NETSETUP_JOIN_UNSECURE | Performs an unsecured join. |
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 or one of the Win32 error codes.
Value | Meaning |
---|---|
ERROR_INVALID_PARAMETER | A parameter is incorrect. |
ERROR_NO_SUCH_DOMAIN | The specified domain did not exist. |
NERR_SetupAlreadyJoined | The computer is already joined to a domain. |
NERR_InvalidWorkgroupName | The specified workgroup name is not valid. |
Different processes, or different threads of the same process, should not call the NetJoinDomain function at the same time. This situation can leave the computer in an inconsistent state.
If you encounter a problem during a join operation, you should not delete a computer account and immediately follow the deletion with another join attempt. This can lead to replication-related problems that are difficult to investigate. When you delete a computer account, wait until the change has replicated to all domain controllers before attempting another join operation.
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Unsupported.
Header: Declared in Lmjoin.h; include Lm.h.
Library: Use Netapi32.lib.
Network Management Overview, Network Management Functions, NetUnjoinDomain