Merge pull request #223 from crazy-max/master

Force updateHostsWindows.bat to be launched as Administrator
This commit is contained in:
Steven Black
2016-12-21 23:50:46 -05:00
committed by GitHub
2 changed files with 44 additions and 29 deletions
+1 -22
View File
@@ -225,30 +225,9 @@ sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder
|`makeHostsWindows.bat` BATCH file will create various alternate hosts files by combining and adding the gambling, porn, and social media extensions. You need to be connected to the Internet. This file REQUIRED installed Python 3.5.x runtime environment in Windows System. Launch this file as normal user.|
:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|Run `updateHostsWindows.bat` BATCH file in Command Prompt with Administrator privileges in repository directory for easy update, replace hosts file and reload DNS cache in Windows System. You need to be connected to the Internet. This file REQUIRED installed Python 3.5.x runtime environment in Windows System.|
|Run `updateHostsWindows.bat` BATCH file will replace hosts file and reload DNS cache in Windows System. You need to be connected to the Internet. This file REQUIRED installed Python 3.5.x runtime environment in Windows System.|
:---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|WARNING: Don't run these BAT files directly or from popup menu. You have been warned.|
:--------------------------------------------------------------------------------------
Open a Command Prompt in directory where are files from this repository:
**Windows XP**: Start -> Run -> `cmd`
**Windows Vista, 7**: Start Button -> type `cmd` -> right-click Command Prompt ->
"Run as Administrator"
**Windows 8**: Start -> Swipe Up -> All Apps -> Windows System -> right-click Command Prompt ->
"Run as Administrator"
**Windows 10**: Start Button -> type `cmd` -> right-click Command Prompt ->
"Run as Administrator"
and run command:
```
updateHostsWindows.bat
```
|If you want using huge hosts file with merged [hphosts](https://www.hosts-file.net) (NOT INCLUDED HERE) you need to DISABLE and STOP `Dnscache` service before you replace hosts file in Windows Systems. You have been warned.|
:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+43 -7
View File
@@ -1,9 +1,41 @@
:: This script will create in first running backup of ORIGINAL/CURRENT hosts file in hosts.skel file.
:: If hosts.skel file exists, then NEW copy with customized unified hosts file will be copied to proper path.
:: Next DNS Cache will be refreshed.
:: YOU NEED RUNNING THIS BAT FILE IN COMMAND LINE PROMPT WITH ADMINISTRATOR PRIVILIGES
:: THIS BAT FILE WILL BE LAUNCHED WITH ADMINISTRATOR PRIVILIGES
@ECHO OFF
VER | FINDSTR /L "5.1." > NUL
IF %ERRORLEVEL% EQU 0 GOTO START
VER | FINDSTR /L "5.2." > NUL
IF %ERRORLEVEL% EQU 0 GOTO START
:UAC_ADMIN
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%ERRORLEVEL%' NEQ '0' (
ECHO Requesting administrative privileges...
GOTO UAC_PROMPT
) else (
GOTO ADMIN
)
:UAC_PROMPT
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%TEMP%\getadmin.vbs"
ECHO UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%TEMP%\getadmin.vbs"
"%TEMP%\getadmin.vbs"
EXIT /B
:ADMIN
if exist "%TEMP%\getadmin.vbs" (
DEL "%TEMP%\getadmin.vbs"
)
pushd "%CD%"
CD /D "%~dp0"
CD %CD%
%COMSPEC% /c "updateHostsWindows.bat" start
EXIT
:START
if not exist "%WINDIR%\py.exe" (
ECHO :: ERROR :: Python 3.5 Runtime NOT FOUND...
ECHO :: ERROR :: Download and install lastest Python 3.5 for Windows from https://www.python.org/downloads/
@@ -11,7 +43,8 @@ if not exist "%WINDIR%\py.exe" (
GOTO END
) ELSE (
GOTO PY35RT
)
)
:PY35RT
if not exist "%LOCALAPPDATA%\Programs\Python\Python35\Python35.dll" (
ECHO :: ERROR :: Python 3.5 Runtime NOT FOUND...
@@ -22,15 +55,18 @@ if not exist "%LOCALAPPDATA%\Programs\Python\Python35\Python35.dll" (
ECHO :: INFO :: Python 3.5 Runtime was found...
ECHO :: INFO :: Running main script...
GOTO DNSCHECK
)
)
:DNSCHECK
if not exist "%WINDIR%\System32\drivers\etc\hosts.skel" (
COPY %WINDIR%\System32\drivers\etc\hosts %WINDIR%\System32\drivers\etc\hosts.skel
GOTO :CLEARDNS
)
:CLEARDNS
updateHostsFile.py -a
COPY hosts %WINDIR%\System32\drivers\etc\
ipconfig /flushdns
GOTO END
updateHostsFile.py -a
COPY hosts %WINDIR%\System32\drivers\etc\
ipconfig /flushdns
GOTO END
:END