Platform SDK: Network Management

NetRenameMachineInDomain

The NetRenameMachineInDomain function changes the name of a computer in a domain.

Security Requirements

Renaming a domain computer can be performed only by a member of the Administrators local group on the target computer. If you call the NetRenameMachineInDomain function remotely, you must supply credentials because you cannot delegate credentials under these circumstances.

NET_API_STATUS NetRenameMachineInDomain(
  LPCWSTR lpServer,
  LPCWSTR lpNewMachineName,
  LPCWSTR lpAccount,
  LPCWSTR lpPassword,
  DWORD fRenameOptions
);

Parameters

lpServer
[in] Pointer to a constant null-terminated Unicode character string that specifies the name of the computer on which to call the function. The string must begin with \\. If this parameter is NULL, the local computer is used.
lpNewMachineName
[in] Pointer to a constant null-terminated Unicode character string that specifies the new name of the computer. If specified, the local computer name is changed as well. If this parameter is NULL, the function assumes you have already called the SetComputerNameEx function.
lpAccount
[in] Pointer to a constant null-terminated Unicode character string that specifies an account name to use when connecting to the domain controller. If this parameter is NULL, the caller's context is used.
lpPassword
[in] If the lpAccount parameter specifies an account name, this parameter must point to the password to use when connecting to the domain controller. Otherwise, this parameter must be NULL.
fRenameOptions
[in] Specifies the rename options. If this parameter is NETSETUP_ACCT_CREATE, the function renames the account in the domain.

Return Values

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.
NERR_SetupNotJoined The computer is not currently joined to a domain.
NERR_SetupDomainController This computer is a domain controller and cannot be unjoined from a domain.

Remarks

Different processes, or different threads of the same process, should not call the NetRenameMachineInDomain function at the same time. This situation can leave the computer in an inconsistent state.

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Unsupported.
  Header: Declared in Lmjoin.h; include Lm.h.
  Library: Use Netapi32.lib.

See Also

Network Management Overview, Network Management Functions, SetComputerNameEx, NetUnjoinDomain