SetComputerNameEx (kernel32)
Last changed: -129.186.82.93

.
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:

    public class renamefull
    {
    [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 fullrename(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