forked from StevenBlack/hosts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updateHostsWindows.bat
30 lines (25 loc) · 1008 Bytes
/
updateHostsWindows.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
:: This script will first create a backup of the original or current hosts
:: file and save it in a file titled "hosts.skel"
::
:: If "hosts.skel" exists, the new hosts file with the customized unified hosts
:: will be copied to the proper path. Next, the DNS cache will be refreshed.
::
:: THIS BAT FILE MUST BE LAUNCHED WITH ADMINISTRATOR PRIVILEGES
@ECHO OFF
TITLE Update Hosts
:: Check if we are administrator. If not, exit immediately.
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if %ERRORLEVEL% NEQ 0 (
ECHO This script must be run with administrator privileges!
ECHO Please launch command prompt as administrator. Exiting...
EXIT /B 1
)
if not exist "%WINDIR%\System32\drivers\etc\hosts.skel" (
COPY %WINDIR%\System32\drivers\etc\hosts %WINDIR%\System32\drivers\etc\hosts.skel
)
:: Update hosts file
python updateHostsFile.py -a
:: Move new hosts file in-place
COPY hosts %WINDIR%\System32\drivers\etc\
:: Flush the DNS cache
ipconfig /flushdns