NetSetPrimaryComputerName function (lmjoin.h)

The NetSetPrimaryComputerName function sets the primary computer name for the specified computer.

Syntax

NET_API_STATUS NET_API_FUNCTION NetSetPrimaryComputerName(
  [in, optional] LPCWSTR Server,
  [in]           LPCWSTR PrimaryName,
  [in, optional] LPCWSTR DomainAccount,
  [in, optional] LPCWSTR DomainAccountPassword,
  [in]           ULONG   Reserved
);

Parameters

[in, optional] Server

A pointer to a constant string that specifies the name of the computer on which to execute this function. If this parameter is NULL, the local computer is used.

[in] PrimaryName

A pointer to a constant string that specifies the primary name to set. This name must be in the form of a fully qualified DNS name.

[in, optional] DomainAccount

A pointer to a constant string that specifies the domain account to use for accessing the machine account object for the computer specified in the Server parameter in Active Directory. If this parameter is NULL, then the credentials of the user executing this routine are used.

This parameter is not used if the server to execute this function is not joined to a domain.

[in, optional] DomainAccountPassword

A pointer to a constant string that specifies the password matching the domain account passed in the DomainAccount parameter. If this parameter is NULL, then the credentials of the user executing this routine are used.

This parameter is ignored if the DomainAccount parameter is NULL. This parameter is not used if the server to execute this function is not joined to a domain.

[in] Reserved

Reserved for future use. This parameter should be NULL.

Return value

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 system error codes.

Return code Description
ERROR_ACCESS_DENIED
Access is denied. This error is returned if the caller was not a member of the Administrators local group on the target computer.
ERROR_INVALID_NAME
A name parameter is incorrect. This error is returned if the PrimaryName parameter does not contain valid name.
ERROR_INVALID_PARAMETER
A parameter is incorrect. This error is returned if the DomainAccount parameter does not contain a valid domain. This error is also returned if the DomainAccount parameter is not NULL and the DomainAccountPassword parameter is not NULL but does not contain a Unicode string.
ERROR_NOT_ENOUGH_MEMORY
Not enough memory is available to process this command.
ERROR_NOT_SUPPORTED
The request is not supported. This error is returned if the target computer specified in the Server parameter on which this function executes is running on Windows 2000 and earlier.
NERR_WkstaNotStarted
The Workstation service has not been started.
RPC_S_CALL_IN_PROGRESS
A remote procedure call is already in progress for this thread.
RPC_S_PROTSEQ_NOT_SUPPORTED
The remote procedure call protocol sequence is not supported.

Remarks

The NetSetPrimaryComputerName function is supported on Windows XP and later.

The NetSetPrimaryComputerName function is used as part of computer rename operations. The specified name will be removed from the alternate name list configured for the target computer and configured as the primary name. The computer account name will be changed to match the primary name. The previous primary computer name is moved to the alternate computer name list configured for the computer.

The NetSetPrimaryComputerName function requires that the caller is a member of the Administrators local group on the target computer.

Requirements

Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header lmjoin.h (include Lm.h)
Library Netapi32.lib
DLL Netapi32.dll

See also

NetAddAlternateComputerName

NetEnumerateComputerNames

NetJoinDomain

NetRemoveAlternateComputerName

NetRenameMachineInDomain

NetUnjoinDomain

SetComputerNameEx