无法使用批处理文件覆盖hosts文件

时间:2012-07-29 00:45:54

标签: batch-file hosts

我试图用批处理脚本

清除hosts文件的所有内容

这是我的代码:

@echo off 
cd %SYSTEMDRIVE%:\Windows\System32\drivers\etc
takeown /f hosts
icacls hosts /grant %username%:w
echo > hosts

批处理执行后,hosts文件不受影响。我应该改变什么?

1 个答案:

答案 0 :(得分:0)

这是我发现的解决方案。不确定它为什么会起作用,但确实如此,主要是

@echo off 
takeown /f C:\Windows\System32\drivers\etc\hosts
icacls C:\Windows\System32\drivers\etc\hosts /grant %username%:w
echo # > C:\Windows\System32\drivers\etc\hosts
echo.
echo.
ipconfig /flushdns
echo.
echo.
echo All sites restored!
pause

如果我尝试打开一个新的浏览器,它的效果很好。如果我有一个浏览器当前打开,它不起作用。有什么建议吗?

(使用Chrome)

相关问题