How do I change the hostname in C #?

I want to change hostname by code in C #. The operating system is xp.

Thank.

+2


source to share


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


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







All Articles