注意:需要获得管理员权限执行,且后缀为 .bat
@echo off
setlocal enabledelayedexpansionset url=被替换的域名set ip=替换的域名set strNew=%ip% %url%set browser= %~dp0\Application\360chrome.exeecho 获取Administrator权限
cacls.exe "%SystemDrive%\System Volume Information" >nul 2>nulif %errorlevel%==0 goto Adminif 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" /fif exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"exit:Admin
echo 成功取得Administrator权限echo 修改hosts文件
set file=%SystemRoot%\system32\drivers\etc\hostsattrib -R %file%for /f "delims=` tokens=*" %%1 in ('findstr "%url%" %file%') do (
set valueFlag=%%1)if not defined valueFlag (
@echo.>>%file% @echo %ip% %url% >>%file%) else ( for /f "tokens=*" %%j in (%file%) do ( set "tmp=%%j" if not !tmp!.==. ( set "tmp=!tmp:%valueFlag%=%strNew%!" echo !tmp!>>temp.txt ) ) move /y temp.txt %file%)echo 修改hosts文件成功start %browser% http://%ip%/nmcweb/portal/