@echo off title Thay the file hosts Windows - Auto Run :: Tu dong kiem tra va chay voi quyen Administrator >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" if '%errorlevel%' NEQ '0' ( echo Requesting administrator privileges... goto UACPrompt ) else ( goto gotAdmin ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" exit /B :gotAdmin pushd "%CD%" CD /D "%~dp0" cls echo ============================================= echo TU DONG THAY THE FILE HOSTS WINDOWS echo ============================================= set HOSTS_FILE=%SystemRoot%\System32\drivers\etc\hosts set TEMP_FILE=%TEMP%\hosts_new_%RANDOM%.txt echo Dang xu ly file hosts: %HOSTS_FILE% :: Tu dong tao backup copy "%HOSTS_FILE%" "%HOSTS_FILE%.backup.%date:~6,4%-%date:~3,2%-%date:~0,2%" >nul 2>&1 echo [OK] Da tao backup file hosts :: Tao noi dung moi echo # Copyright (c) 1993-2009 Microsoft Corp. > "%TEMP_FILE%" echo # >> "%TEMP_FILE%" echo # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. >> "%TEMP_FILE%" echo # >> "%TEMP_FILE%" echo # localhost name resolution is handled within DNS itself. >> "%TEMP_FILE%" echo 127.0.0.1 localhost >> "%TEMP_FILE%" echo ::1 localhost >> "%TEMP_FILE%" echo. >> "%TEMP_FILE%" echo # Custom entries - Them cac entry tuy chinh o day >> "%TEMP_FILE%" echo # 127.0.0.1 example.com >> "%TEMP_FILE%" echo # 127.0.0.1 www.example.com >> "%TEMP_FILE%" :: Thay the file hosts copy "%TEMP_FILE%" "%HOSTS_FILE%" >nul 2>&1 if %errorlevel% equ 0 ( echo [OK] Da thay the file hosts thanh cong! ) else ( echo [LOI] Khong the thay the file hosts! del "%TEMP_FILE%" >nul 2>&1 exit /b 1 ) :: Don dep del "%TEMP_FILE%" >nul 2>&1 :: Clear DNS cache ipconfig /flushdns >nul 2>&1 echo [OK] Da clear DNS cache echo. echo [HOAN THANH] File hosts da duoc thay the tu dong! echo File se tu dong dong sau 2 giay... timeout /t 2 /nobreak >nul exit /b 0