Search code examples
windowscurlbatch-filehosts

Batch script to update hosts file on boot-up using curl


I am trying to get a .bat script to run on boot-up and purge the hosts file with a new one.

I have this working on Windows Server 2008 Standard X86 and it has been working consistently for over a year. I installed 'curl', hard linked it to System32 and schedule the following .bat script using local group policy:

curl x.x.x.x/latest/hosts > C:\Windows\System32\drivers\etc\hosts

Now I want to get the same script working on windows server 2008 R2. I have the same thing setup and it works if I double-click the .bat file. However, when the script runs on startup via GPO, it simply wipes the hosts file completely and I have to login manually and double-click the .bat script.

Any idea what's causing this? Is it a difference between Server 2008 R2 and Server 2008 STD?


Solution

  • Try

    curl.exe x.x.x.x/latest/hosts > C:\Windows\System32\drivers\etc\hosts.tmp
    move C:\Windows\System32\drivers\etc\hosts.tmp C:\Windows\System32\drivers\etc\hosts