[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. '该脚本要求执行用户有本地管理员权限
  2. Set fso = CreateObject("Scripting.FileSystemObject")
  3. Set fd = fso.GetSpecialFolder(1)
  4. HostsFile = fd & "\Drivers\etc\Hosts"
  5. Set objFile = fso.GetFile(HostsFile)
  6. If objFile.Attributes And 1 Then
  7.     objFile.Attributes = objFile.Attributes -1
  8. End If
  9. Set f = fso.OpenTextFile(HostsFile, 1)
  10. tmp = f.ReadAll
  11. If InStr (tmp, "202.102.101.105") <> 0 Then
  12.     Set regEx = New RegExp
  13.     regEx.Global = True
  14.     regEx.Pattern = "[^\r\n]*202\.102\.101\.(105|107|108).+[\r\n]?"
  15.     txt = regex.replace(tmp,"")
  16.     Set regEx = Nothing
  17.     f.Close
  18.     Set f = fso.OpenTextFile(HostsFile, 2)
  19.     f.Write txt
  20.     f.Close
  21. End If
复制代码

TOP

回复 3# a000001

这样的事当然用批处理
  1. @echo off
  2. >"%tmp%\$" more +7 %0
  3. set "fd=%windir%\System32\Drivers\etc"
  4. attrib -r "%fd%\hosts"
  5. findstr /v /g:"%tmp%\$" "%fd%\hosts">"%fd%\$"
  6. move "%fd%\$" "%fd%\hosts"
  7. pause&exit
  8. 127.0.0.1 mcfg.sandai.net
  9. 127.0.0.1 211.94.190.80
  10. 127.0.0.1 advstat.xunlei.com
  11. 123.87.86.5 biz5.sandai.net
  12. 527.66.13.125 cknum.sandai.net
  13. 110.45.215.113 cl.kankan.xunlei.com
  14. 127.0.0.1 float.sandai.net
  15. 127.0.0.1 mcfg.sandai.net
  16. 180.70.134.154 mtips.xunlei.com
  17. 127.0.0.1 pubstat.sandai.net
  18. 216.58.221.74 recommend.xunlei.com
  19. 127.0.0.1 wy.xunlei.com
  20. 110.45.229.148 buy.safe.xunlei.com
复制代码

TOP

回复 5# a000001
  1. On Error Resume Next
  2. Set fso = CreateObject("Scripting.FileSystemObject")
  3. Set dict = CreateObject("Scripting.Dictionary")
  4. Set f = fso.OpenTextFile(wscript.scriptfullname, 1)
  5. Do Until f.AtEndOfStream
  6.     str = Trim(f.ReadLine)
  7.     IF Left(str,1)="'" Then dict.Add mid(str,2), "1"
  8. Loop
  9. f.Close
  10. Set fso = CreateObject("Scripting.FileSystemObject")
  11. Set fd = fso.GetSpecialFolder(1)
  12. HostsFile = fd & "\Drivers\etc\Hosts"
  13. Set objFile = fso.GetFile(HostsFile)
  14. If objFile.Attributes And 1 Then
  15.     objFile.Attributes = objFile.Attributes -1
  16. End If
  17. Set f = fso.OpenTextFile(HostsFile, 1)
  18. Do Until f.AtEndOfStream
  19.     str = f.ReadLine
  20.     If not dict.Exists(Trim(str)) Then
  21.     txt = txt & str & vbCrLf
  22. End If
  23. Loop
  24. f.Close
  25. Set f = fso.OpenTextFile(HostsFile, 2)
  26. f.Write txt
  27. f.Close
  28. '127.0.0.1 mcfg.sandai.net
  29. '127.0.0.1 211.94.190.80
  30. '127.0.0.1 advstat.xunlei.com
  31. '123.87.86.5 biz5.sandai.net
  32. '527.66.13.125 cknum.sandai.net
  33. '110.45.215.113 cl.kankan.xunlei.com
  34. '127.0.0.1 float.sandai.net
  35. '180.70.134.154 mtips.xunlei.com
  36. '127.0.0.1 pubstat.sandai.net
  37. '216.58.221.74 recommend.xunlei.com
  38. '127.0.0.1 wy.xunlei.com
  39. '110.45.229.148 buy.safe.xunlei.com
复制代码
1

评分人数

TOP

回复 7# a000001


    嗯,你添加新的域名时先检测是否已存在,是就不添加;或者,两个都保留,不删就是

TOP

回复 9# a000001

嗯,可以,别问我怎么做到

TOP

回复 11# a000001

del /q "%tmp%\$"
pause&exit
1

评分人数

TOP

回复 13# a000001

都可以,别问我怎么做到

TOP

返回列表