我認爲Windows的API可能是幫助在Windows 2000:使用SetComputerNameEx
:
BOOL WINAPI SetComputerNameEx(
__in COMPUTER_NAME_FORMAT NameType,
__in LPCTSTR lpBuffer
);
該樣本是根據樣本上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;
}
}
另外要調用WinAPI,您也可以使用Process.Start
與netsh
命令的組合,如here所述。
阿哈,我敢肯定這會奏效,我會盡快接受這一點。 – 2010-02-25 12:18:00