2019-09-04 16:44:17 +02:00
|
|
|
::
|
2017-05-18 05:17:37 +02:00
|
|
|
:: This script will first create a backup of the original or current hosts
|
|
|
|
:: file and save it in a file titled "hosts.skel"
|
2017-05-16 19:47:54 +02:00
|
|
|
::
|
2017-05-18 05:17:37 +02:00
|
|
|
:: 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.
|
2017-05-16 19:47:54 +02:00
|
|
|
::
|
|
|
|
:: THIS BAT FILE MUST BE LAUNCHED WITH ADMINISTRATOR PRIVILEGES
|
2019-09-04 16:44:17 +02:00
|
|
|
:: Admin privileges script based on https://stackoverflow.com/a/10052222
|
|
|
|
::
|
|
|
|
::
|
2016-12-22 16:30:26 +01:00
|
|
|
@ECHO OFF
|
|
|
|
TITLE Update Hosts
|
|
|
|
|
2017-05-16 19:47:54 +02:00
|
|
|
:: Check if we are administrator. If not, exit immediately.
|
2019-09-04 16:44:17 +02:00
|
|
|
:: BatchGotAdmin
|
|
|
|
:-------------------------------------
|
|
|
|
REM --> Check for permissions
|
|
|
|
IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
|
|
|
|
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
|
|
|
|
) ELSE (
|
2017-05-16 19:47:54 +02:00
|
|
|
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
|
2016-12-22 16:30:26 +01:00
|
|
|
)
|
|
|
|
|
2019-09-04 16:44:17 +02:00
|
|
|
REM --> If error flag set, we do not have admin.
|
|
|
|
if '%errorlevel%' NEQ '0' (
|
|
|
|
echo Requesting administrative privileges...
|
|
|
|
goto UACPrompt
|
|
|
|
) else ( goto gotAdmin )
|
|
|
|
|
|
|
|
:UACPrompt
|
|
|
|
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
|
|
|
|
set params= %*
|
|
|
|
echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs"
|
|
|
|
|
|
|
|
"%temp%\getadmin.vbs"
|
|
|
|
del "%temp%\getadmin.vbs"
|
|
|
|
exit /B
|
|
|
|
|
|
|
|
:gotAdmin
|
|
|
|
pushd "%CD%"
|
|
|
|
CD /D "%~dp0"
|
2016-12-22 16:30:26 +01:00
|
|
|
|
2019-09-04 16:44:17 +02:00
|
|
|
:BackupHosts
|
|
|
|
:: Backup default hosts file
|
|
|
|
if not exist "%WINDIR%\System32\drivers\etc\hosts.skel" (
|
|
|
|
COPY %WINDIR%\System32\drivers\etc\hosts %WINDIR%\System32\drivers\etc\hosts.skel
|
|
|
|
)
|
2017-05-16 19:47:54 +02:00
|
|
|
|
2019-09-04 16:44:17 +02:00
|
|
|
:UpdateHosts
|
|
|
|
:: Update hosts file
|
|
|
|
python updateHostsFile.py --auto --minimise
|
|
|
|
|
|
|
|
:: Move new hosts file in-place
|
|
|
|
COPY hosts %WINDIR%\System32\drivers\etc\
|
2016-12-22 16:30:26 +01:00
|
|
|
|
2019-09-04 16:44:17 +02:00
|
|
|
:: Flush the DNS cache
|
|
|
|
ipconfig /flushdns
|
|
|
|
|
|
|
|
:: Summary note
|
|
|
|
pause
|