I think the Windows API might be of help on Windows 2000: Use SetComputerNameEx
:
BOOL WINAPI SetComputerNameEx(
__in COMPUTER_NAME_FORMAT NameType,
__in LPCTSTR lpBuffer
);
This sample is based on the sample on pinvoke.net:
public class RenameComputer
{
[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 Rename(string name)
{
bool result = SetComputerNameEx(COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, name);
if (!result)
throw new Win32Exception();
return result;
}
}
In addition to p-invoking the WinAPI you might also use Process.Start
in combination with the netsh
command as described here.