做个笔记。
@echo off ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::ADMIN POWER(start):::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: >nul 2>&1 "%SYSTEMROOT%system32cacls.exe" "%SYSTEMROOT%system32configsystem" if '%errorlevel%' NEQ '0' ( 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" exit /B :gotAdmin if exist "%temp%getadmin.vbs" ( del "%temp%getadmin.vbs" ) ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::ADMIN POWER(end)::::::::::::::::::::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: set a=192.168.13.11 chenglee-001 set file=C:WindowsSystem32driversetchosts ::(echo.) >> %file% (echo %a%) >> %file% echo 写入成功...5秒后退出窗口 choice /t 5 /d y /n >nul ::pause exit
第一块获取管理员admin权限, 第二块实现写入, 去掉不相关空格。