SetComputerName (kernel32)
Last changed: -64.239.136.245

.
Summary
Sets a NetBIOS or DNS name for the local computer.

C# Signature:

[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Auto)]
static extern bool SetComputerNameEx(COMPUTER_NAME_FORMAT NameType,
   string lpBuffer);

User-Defined Types:

COMPUTER_NAME_FORMAT

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    static extern bool SetComputerNameEx(COMPUTER_NAME_FORMAT NameType,
    string lpBuffer);

    enum COMPUTER_NAME_FORMAT
    {
        ComputerNameNetBIOS,
        ComputerNameDnsHostname,
        ComputerNameDnsDomain,
        ComputerNameDnsFullyQualified,
        ComputerNamePhysicalNetBIOS,
        ComputerNamePhysicalDnsHostname,
        ComputerNamePhysicalDnsDomain,
        ComputerNamePhysicalDnsFullyQualified,
    }

    //ComputerNamePhysicalDnsHostname used to rename the computer name and netbios name before domain join
    public static bool RenameComputer(string name)
    {
        try
        {
        return SetComputerNameEx(COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, name);
        }
        catch (Exception)
        {
        return false;
        }
    }

Alternative Managed API:

Do you know one? Please contribute it!

Documentation