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

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