However, it appears that this key is somehow ignored by my system (Windows 7 64 bit) and the default location %SystemRoot%\system32\drivers\etc is still the one where the hosts file is read.
I notice it because any changes made to the hosts file in the default location are detected (I check it with the ping command) and any changes to the new location are simply ignored.
I have copied and pasted the hosts file with different values between the default and new folder, so I guess it is not a problem with the hosts file having the wrong format. I also copied and paste the new folder path to the registry key so it is also not a problem of having misspelled the folder path, either. I also restarted the computer after changing the registry key.
Any ideas of what could be the problem? Thanks in advance for the help!
Thank you very much for your reply, Hawkeye22! I belonged to the people that thought that SysWOW64 contained the 64 bit executables, and I had absolutely no clue of this redirection taking place when using a 32 bit application. I learned thanks to you some important things about my OS today.
However, I fail to see how this affect my problem. If I made some changes to the hosts file in the Windows\System32\drivers\etc folder adding some new sites to be redirected and these changes affected the behaviour of the ping command to the added sites, it means that, even if it was just by chance (because as I say I had no clue of this redirection for 32 bit apps), I had landed in the right folder and the right hosts file. It is not a problem of the default folder location, but rather of my attempt to modify it to a new folder by changing the registry key mentioned in my first post. If you do think it is indeed related, can you please further elaborate so that I better understand your point.
In any case, as I say, thank you for this insight in the SysWOW64 folder. Very interesting indeed!
Not the solution, but the direction (to lazy to search): there is also some sort of redirection for the registry and that is for security reasons. To change keys like the path to the host file you need to at least switch of the UAC for the admin account. Otherwise it would be very easy for a virus/trojan to change the registry. :-)
No idea, what else is needed, but what you see in regedit is NOT always what win processes.
I posted a link to that last article because I could not find the registry key you were editing in any articles mentioning the hosts file, so at this point I don't know if moving the hosts file is doable.
I did however want to point out that if UAC is turned on, there is some redirection taking place at the folder level and as noidea_77 pointed out, also registry redirection. Turning UAC off (even temporarily) is the only way to make sure redirection isn't taking place.
Strange things you are describing that I was most certainly not aware of! I will then when I get back home try as you say and disable the UAC temporarily to make the changes in the registry and I will let you know whether this works. To tell you the truth, I can't understand what is the purpose of showing values in the registry that do not correspond to the real values being used. One thing is to require administrative rights to make changes in the registry and I can see the benefit to avoid a virus/trojan to take control of the system, but quite another to trick the user by showing him values in the registry that do not correspond to the ones used by the system. What is the benefit of it? I can see more dangers than benefits out of it.
I got the registry value I was referring to in my first post from here
I tried to modify the registry first disabling the UAC as you suggested following the instructions here. With the UAC disabled (at least no more messages popped up when making changes), I got into the registry. The key had already the amended value and pointed to the new folder, but anyway I changed it again a couple of times to make sure the change took place with UAC disabled. Then I tried to change the hosts file in the folder indicated in the registry key and the changes were ignored when making a ping. I then made changes in the hosts file in the default folder and the changes did affect the ping behaviour. So the hosts file in the default folder is still the valid hosts file. Any idea of what I am doing wrong?
Where did you find the information for that registry key? I can still find no information on changing the location of the hosts file, even on microsoft's site. It may not be possible to do so and why would you want to move it?
Maybe you are right and it is not possible to alter the location, but there are several sites pointing to this possibility. This is why I tend to think it must be possible. I already put one link in the reply I made to you both.
The actual location defined in the following Registry key:
There is also a Microsoft site stating the same here, even if I think it is not an "official" statement:
The Hosts file is normally located at C:\Windows\System32\Drivers\etc\ as you well know. If it is not there, look for its location in registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath.
Regarding why, I don't only have Windows 7 but also Windows XP sitting on another partition. I simply wanted both to share the same hosts file, so that I don't have to repeat the same changes to the hosts file in both OSs. As Windows 7 is in a SSD, I preferred to move the hosts file to the HDD.
So I guess there is no way to change the hosts file location then. Amazing how many links related to windows 7, even in a Microsoft page, state that the reg key mentioned above points to the folder where the hosts file is located.
I will try to use a junction folder and see if it works. Otherwise, I will stick to the default location. It is not that much of a problem.