CLOSE  
sTarget = WScript.Arguments(0)  'First command-line arg to script.
sLog = WScript.Arguments(1)     'Second command-line arg to script.

If ClearEventLog(sTarget, sLog) Then          'Function returns true if operation successful.
    WScript.Echo sLog & " log cleared on " & sTarget
Else
    WScript.Echo sLog & " log NOT cleared on " & sTarget
End If

Function ClearEventLog(sComputer, sLogName)
    On Error Resume Next
    Set oWMI = GetObject("WinMgmts:{(Security)}!\\" & sComputer & "\root\cimv2")
    Set cLogFile = oWMI.ExecQuery("SELECT * FROM Win32_NTEventLogFile WHERE LogFileName = " & "'" & sLogName & "'")
    For Each oLog In cLogFile
        iError = oLog.ClearEventLog()
    Next
    If iError = 0 And Err.Number = 0 Then ClearEventLog = True Else ClearEventLog = False
End Function

図5●Windowsイベント・ログの中身を消去する「ClearEventLog.vbs」

Copyright (C) 2004 Nikkei Business Publications, Inc. All rights reserved.