0 out of 1 rated this helpful - Rate this topic

NetSetPrimaryComputerName function

Applies to: desktop apps only

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

Syntax

NET_API_STATUS  NetSetPrimaryComputerName(
  __in_opt  LPCWSTR Server,
  __in      LPCWSTR PrimaryName,
  __in_opt  LPCWSTR DomainAccount,
  __in_opt  LPCWSTR DomainAccountPassword,
  __in      ULONG Reserved
);

Parameters

Server [in, optional]

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.

PrimaryName [in]

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.

DomainAccount [in, optional]

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.

DomainAccountPassword [in, optional]

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 [in]

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 codeDescription
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

Minimum supported client

Windows XP

Minimum supported server

Windows Server 2003

Header

Lmjoin.h (include Lm.h)

Library

Netapi32.lib

DLL

Netapi32.dll

See also

NetAddAlternateComputerName
NetEnumerateComputerNames
NetJoinDomain
NetRemoveAlternateComputerName
NetRenameMachineInDomain
NetUnjoinDomain
SetComputerNameEx

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ