35

I understand that changing the host name/computer name for a Windows based machine (Client or Server) requires a reboot. I realize that once a computer name is changed, a pending machine name is stored in the system registry and is applied on next boot. I was not able to find much technical documentation on exactly WHY this was required.

Can someone please point me in the right direction on the technical challenges behind why a host name change is not complete without a system reboot ?

2
  • 1
    Added a comment to the accepted answer with a link to an MSDN article on why a reboot is required.
    – Ameer Deen
    Commented Aug 19, 2013 at 5:15
  • I wouldn't say that the linked article explains why a reboot is required. After all, if it was just a matter of copying it to that other location, then the command to change the name could go ahead and copy it. The key sentence in the accepted answer is "Many Windows services and applications, both those written by Microsoft as well as 3rd party, that use the system's hostname, typically only read it once at startup and never read it again." Commented Aug 30, 2016 at 13:15

2 Answers 2

60

You don't have to restart immediately after renaming the machine... just don't expect every service and function to pick up on the new name.

Things such as system environment variables are read once, at system startup. If you change those variables, the various components of Windows won't pick up on them until they're restarted. Some of those components are so deeply integrated with the OS, you might as well restart the entire OS.

Many Windows services and applications, both those written by Microsoft as well as 3rd party, that use the system's hostname, typically only read it once at startup and never read it again.

I know if I was writing an application that read the machine's hostname, it would be pretty silly of me to periodically poll for it just in case it changed.

In an operating system such as Linux, you see the same thing. You can change the hostname without rebooting, but you do have to restart some very basic components of the system in order to get them to pick up on the new name. Linux is more modular than Windows, although Windows has come a long way in terms of modularity.

One way to detect whether a Windows system is pending a computer rename operation is to check the registry. If the contents of

HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName

and

HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName

are not the same, that means the system has a pending rename operation that will complete the next time the system reboots.

1
  • 11
    Thanks for the tip Ryan. I looked up the code for System.Environment.MachineName (using dotnetpeek). It uses the GetComputerName function in Kernel32.dll which: "Retrieves the NetBIOS name of the local computer. This name is established at system startup, when the system reads it from the registry." (msdn.microsoft.com/en-us/library/windows/desktop/…). In other words, you're right its simply cached on startup. Just wanted some documentation to back it up. Thanks.
    – Ameer Deen
    Commented Aug 18, 2013 at 17:58
3

Here's a script for skipping the reboot: https://gist.github.com/timnew/2373475

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .