2

我想通过 c# 中的代码更改主机名。操作系统是xp。

谢谢。

4

2 回答 2

2
ManagementClass mComputerSystem = new ManagementClass("Win32_ComputerSystem");
ManagementBaseObject outParams;
ManagementBaseObject objNewComputerName = mComputerSystem.GetMethodParameters("Rename");
objNewComputerName["Name"] = "NEWNAMEHERE";
outParams = mComputerSystem.InvokeMethod("Rename", objNewComputerName, null);
于 2011-02-13T16:26:50.517 回答
1

编辑这些注册表项,然后重新启动。请注意,您可以尝试重新启动计算机浏览器以及服务器和客户端服务,它可能会起作用,但我对此表示怀疑。

HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname
HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName
于 2011-02-13T16:31:40.720 回答