Board logo

标题: [文件操作] [已解决]BAT打开及关闭Hosts,关闭文件时可否触发事件 [打印本页]

作者: Heykuz    时间: 2013-8-8 14:14     标题: [已解决]BAT打开及关闭Hosts,关闭文件时可否触发事件

本人具体事情如下,很多辅助软件都是打开就弹出广告,都不是好东西。所以要把这些网站都写进Hosts,以禁止它打开。最好事后还把HostS给设为只读。

打开代码:(Hosts去只读并打开)
  1. @echo off
  2. attrib -r "%SystemRoot%\system32\drivers\etc\hosts"
  3. start "" "%SystemRoot%\system32\notepad.exe" "%SystemRoot%\system32\drivers\etc\hosts"
  4. exit
复制代码
Hosts设为只读:
  1. @echo off
  2. attrib +r "%SystemRoot%\system32\drivers\etc\hosts"
  3. exit
复制代码
现在想问是,BAT关闭时可否触发事件,如果可以,那我就可以把两段代码合并,关闭BAT时,让Hosts自动设为只读。
作者: tz_being    时间: 2013-8-8 14:28

可以啊:

@echo off
attrib -r "%SystemRoot%\system32\drivers\etc\hosts"
"%SystemRoot%\system32\notepad.exe" "%SystemRoot%\system32\drivers\etc\hosts"
attrib +r "%SystemRoot%\system32\drivers\etc\hosts"
作者: Heykuz    时间: 2013-8-8 14:40

可以啊:

@echo off
attrib -r "%SystemRoot%\system32\drivers\etc\hosts"
"%SystemRoot%\system32\n ...
tz_being 发表于 2013-8-8 14:28



原来是这样,让它先不自动exit,感谢楼上的兄弟。
再问,能隐藏这个黑色DOC窗口么。
作者: Heykuz    时间: 2013-8-8 14:48

不行也没所谓了,我用VBS把它隐藏了。再感谢tz_being,受益非浅。




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2