批处理一键添加hosts文件
此脚本主要用于安装一些学习软件时需屏弊一些网站,双击一键修改。
@echo off
echo 获取Administrator权限
cacls.exe "%SystemDrive%\System Volume Information" >nul 2>nul
if %errorlevel%==0 goto Admin
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
echo Set RequestUAC = CreateObject^("Shell.Application"^)>"%temp%\getadmin.vbs"
echo RequestUAC.ShellExecute "%~s0","","","runas",1 >>"%temp%\getadmin.vbs"
echo WScript.Quit >>"%temp%\getadmin.vbs"
"%temp%\getadmin.vbs" /f
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
exit
:Admin
echo 成功取得Administrator权限
SET NEWLINE=^& echo.
::FIND /C /I "输入你要查询内容" %windir%\system32\drivers\etc\hosts
FIND /C /I "test.com" %windir%\system32\drivers\etc\hosts
::IF %ERRORLEVEL% NEQ 0 ECHO %NEWLINE%^127.0.0.1 输入你要屏弊的域名>>%WINDIR%\system32\drivers\etc\hosts
IF %ERRORLEVEL% NEQ 0 ECHO %NEWLINE%^127.0.0.1 test.com>>%WINDIR%\system32\drivers\etc\hosts
::查看修改结果
type %windir%\system32\drivers\etc\hosts
pause