清空iis log 中自己登录ip的vbs

时间:2021-11-03 09:42:51
  1. Option Explicit  
  2.  
  3. Dim sourcefile,ipaddress,objargs  
  4.  
  5. const destfile="tempfile"  
  6. Const ForWriting = 2  
  7.  
  8. Dim Text  
  9. Dim fso,objNet,ServiceObj  
  10. Dim txtStream, txtStreamOut  
  11.  
  12. Set objArgs = WScript.Arguments  
  13. If objArgs.Count = 2 Then  
  14. sourcefile=objArgs(0)  
  15. ipaddress=objargs(1)  
  16. Else  
  17. wscript.echo "Parameter Error"+ vbcrlf  
  18. wscript.Echo "USAGE:KillLog.vbs LogFileName YourIP."  
  19. wscript.Quit 1  
  20. End If  
  21.  
  22.  
  23. Set fso = CreateObject("Scripting.FileSystemObject")  
  24. if fso.FileExists (sourcefile) then  
  25. Set objNet = WScript.CreateObject( "WScript.Network" )  
  26. Set ServiceObj = GetObject("WinNT://" & objNet.ComputerName & "/w3svc")  
  27. Set objNet=nothing  
  28. ServiceObj.stop  
  29. wscript.sleep 6000  
  30. Set txtStream = fso.OpenTextFile(sourcefile)  
  31. Set txtStreamOut = fso.OpenTextFile(destfile, ForWriting, True)  
  32. Do While Not (txtStream.atEndOfStream)  
  33. Text = txtStream.ReadLine  
  34. if instr(Text,ipaddress)=0 then  
  35. txtStreamOut.WriteLine Text  
  36. end if  
  37. Loop  
  38.  
  39. Set txtStream = Nothing  
  40. Set txtStreamOut = Nothing  
  41.  
  42. WScript.Echo "The log file-- " & sourcefile &" has cleaned your IP!"  
  43. Else  
  44. WScript.Echo "The Log file-- " & sourcefile & " has not found!"  
  45. Wscript.quit  
  46. End If  
  47. fso.Copyfile destfile, sourcefile  
  48. fso.deletefile destfile  
  49. Set fso=Nothing  
  50. ServiceObj.start  
  51. Set ServiceObj = Nothing