How do I change the hostname in C #?
2 answers
ManagementClass mComputerSystem = new ManagementClass("Win32_ComputerSystem");
ManagementBaseObject outParams;
ManagementBaseObject objNewComputerName = mComputerSystem.GetMethodParameters("Rename");
objNewComputerName["Name"] = "NEWNAMEHERE";
outParams = mComputerSystem.InvokeMethod("Rename", objNewComputerName, null);
+2
source to share
Edit these registry keys and reboot. Please note that you can try to just restart the computer browser, server and client services, this might work, but I doubt it.
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Hostname
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NV Hostname
HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName
+1
source to share