Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

NetRenameMachineInDomain (netapi32)
 
.
Summary
Renames an already joined machine on a domain.

C# Signature:

    [DllImport("netapi32.dll", SetLastError=true, CharSet = CharSet.Unicode)]
    internal static extern int NetRenameMachineInDomain(
        string lpServer,
        string lpNewMachineName,
        string lpAccount,
        string lpPassword,
        uint fRenameOptions
        );

VB Signature:

     Declare Function NetRenameMachineInDomain Lib "netapi32.dll" (TODO) As TODO

C# User-Defined Types:

    internal const uint NETSETUP_ACCT_CREATE = 2;

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

lpServer - (in) Pointer to a constant string that specifies the DNS or NetBIOS name of the computer on which to call the function. If this parameter is NULL, the local computer is used. Windows NT: This string must begin with \\.

lpNewMachineName - (in) Pointer to a constant 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 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.

Common Errors :

1326 - ERROR_LOGON_FAILURE

Tips & Tricks:

Please add some!

C# Sample Code:

    [DllImport("netapi32.dll", SetLastError=true, CharSet = CharSet.Unicode)]
    internal static extern int NetRenameMachineInDomain(
        string lpServer,
        string lpNewMachineName,
        string lpAccount,
        string lpPassword,
        uint fRenameOptions
        );

    internal const uint NETSETUP_ACCT_CREATE = 2;

    private string _domainUser = @"domain\domainuser";
    private string _domainPassword = "domainpassword";

    private void RenameMachine()
    {
        //This function will change the current PC's name to "PCNEWNAME" using the given domain account.  This changes it both locally and on the domain.

        int error = 0;
        error = NetRenameMachineInDomain(null, "PCNEWNAME", _domainUser, _domainPassword, NETSETUP_ACCT_CREATE);

        if(error == 0)
        {
            MessageBox.Show("Rename Successful.");
        }
        else
        {
            MessageBox.Show("Rename Failed.\r\nError: " + error.ToString());
        }
    }

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions