Advertisement
tamanmerah

modifyhosts.vbs

Mar 17th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. @echo off
  2. TITLE Modifying your HOSTS file
  3. COLOR F0
  4. ECHO.
  5.  
  6.  
  7. :: BatchGotAdmin
  8. :-------------------------------------
  9. REM --> Check for permissions
  10. >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
  11.  
  12. REM --> If error flag set, we do not have admin.
  13. if '%errorlevel%' NEQ '0' (
  14. echo Requesting administrative privileges...
  15. goto UACPrompt
  16. ) else ( goto gotAdmin )
  17.  
  18. :UACPrompt
  19. echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  20. set params = %*:"="
  21. echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
  22.  
  23. "%temp%\getadmin.vbs"
  24. del "%temp%\getadmin.vbs"
  25. exit /B
  26.  
  27. :gotAdmin
  28. pushd "%CD%"
  29. CD /D "%~dp0"
  30. :--------------------------------------
  31.  
  32. :LOOP
  33. SET Choice=
  34. SET /P Choice="Do you want to modify HOSTS file ? (Y/N)"
  35.  
  36.  
  37. IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
  38.  
  39. ECHO.
  40. IF /I '%Choice%'=='Y' GOTO ACCEPTED
  41. IF /I '%Choice%'=='N' GOTO REJECTED
  42. ECHO Please type Y (for Yes) or N (for No) to proceed!
  43. ECHO.
  44. GOTO Loop
  45.  
  46.  
  47. :REJECTED
  48. ECHO Your HOSTS file was left unchanged>>%systemroot%\Temp\hostFileUpdate.log
  49. ECHO Finished.
  50. GOTO END
  51.  
  52.  
  53. :ACCEPTED
  54. setlocal enabledelayedexpansion
  55. ::Create your list of host domains
  56. set LIST=(diqc.oca wiki.oca)
  57. ::Set the ip of the domains you set in the list above
  58. set diqc.oca=192.168.111.6
  59. set wiki.oca=192.168.111.4
  60. :: deletes the parentheses from LIST
  61. set _list=%LIST:~1,-1%
  62. ::ECHO %WINDIR%\System32\drivers\etc\hosts > tmp.txt
  63. for %%G in (%_list%) do (
  64. set _name=%%G
  65. set _value=!%%G!
  66. SET NEWLINE=^& echo.
  67. ECHO Carrying out requested modifications to your HOSTS file
  68. ::strip out this specific line and store in tmp file
  69. type %WINDIR%\System32\drivers\etc\hosts | findstr /v !_name! > tmp.txt
  70. ::re-add the line to it
  71. ECHO %NEWLINE%^!_value! !_name!>>tmp.txt
  72. ::overwrite host file
  73. copy /b/v/y tmp.txt %WINDIR%\System32\drivers\etc\hosts
  74. del tmp.txt
  75. )
  76. ipconfig /flushdns
  77. ECHO.
  78. ECHO.
  79. ECHO Finished, you may close this window now.
  80. ECHO You should now open Chrome and go to "chrome://net-internals/#dns" (without quotes)
  81. ECHO then click the "clear host cache" button
  82. GOTO END
  83.  
  84. :END
  85. ECHO.
  86. ping -n 11 192.0.2.2 > nul
  87. EXIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement