Windows使用bat脚本获取管理员权限并编辑hosts文件

文件名:编辑hosts.bat

%1 mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0 ::","","runas",1)(window.close)&&exit

if "%1"=="hide" goto CmdBegin
start mshta vbscript:createobject("wscript.shell").run("""%~0"" hide",0)(window.close)&&exit
:CmdBegin

::去除hosts文件只读属性
attrib -R C:\windows\system32\drivers\etc\hosts

::用notepad编辑hosts文件
notepad C:\windows\system32\drivers\etc\hosts

::给hosts文件加上只读属性
attrib +R C:\windows\system32\drivers\etc\hosts

你可能感兴趣的:(windows)