The NetSetPrimaryComputerName function sets the primary computer name for the specified computer.
NET_API_STATUS NET_API_FUNCTION NetSetPrimaryComputerName( LPCWSTR Server, LPCWSTR PrimaryName, LPCWSTR DomainAccount, LPCWSTR DomainAccountPassword, ULONG Reserved );
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.
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.
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.
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.
Reserved for future use. This parameter should be NULL.
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.
||Access is denied. This error is returned if the caller was not a member of the Administrators local group on the target computer.|
||A name parameter is incorrect. This error is returned if the PrimaryName parameter does not contain valid name.|
||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.|
||Not enough memory is available to process this command.|
||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.|
||The Workstation service has not been started.|
||A remote procedure call is already in progress for this thread.|
||The remote procedure call protocol sequence is not supported.|
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.
|Minimum supported client||Windows XP [desktop apps only]|
|Minimum supported server||Windows Server 2003 [desktop apps only]|
|Header||lmjoin.h (include Lm.h)|