【WSH Part1】 イベントログを保存&クリア

WSHの勉強がてらに、イベントログの保存及びクリアができるWSHを作成

環境変数が多い・コードが汚いって・・・突っ込みは無しで・・・・・・・・Orz
少し修正版
コード

                                                                                                                                                                        • -

Option Explicit
'\///////////////////////////////////////////////////////////////////
' Script name イベントログ待避スクリプト
' Script Author 綺羅
' Script Version 1.1
'\///////////////////////////////////////////////////////////////////

'ΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩ
' 使用上の注意
' このスクリプトは、Windows2000/2003/XP上で動作します。
' このスクリプトは、Administrator権限を必要をします。
' このスクリプトを使用して、生じたした損害は一切責任をもちません。
'
'ΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩ

'********************************************************************
'基本関数の定義
'********************************************************************
Dim Strdate
Dim dtmdate

'********************************************************************
'Step1で使用する関数の定義
'********************************************************************
Dim objFS
Dim objFD
Dim objFDD

'********************************************************************
'Step2で使用する関数の定義
'********************************************************************
Dim objComputer
Dim strName
Dim strComputer
Dim objWMIServiceA
Dim objWMIServiceB
Dim objWMIServiceC
Dim colLogFilesA
Dim colLogFilesB
Dim colLogFilesC
Dim objLogfileA
Dim objLogfileB
Dim objLogfileC
Dim errBackupLogA
Dim errBackupLogB
Dim errBackupLogC
'********************************************************************
'関数に変数を定義
'********************************************************************
Strdate = date
dtmdate = Year(Strdate) & Right("0" & Month(Strdate), 2) & Right("0" & Day(Strdate), 2)
objFD = "c:\temp\" 'フォルダの作成先を任意に入力
objFDD = ""& objFD &""& dtmdate &""

'■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
' Step1 フォルダの作成
'■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■

'********************************************************************
'File System objectの生成
'********************************************************************
set objFS = WScript.CreateObject("Scripting.FileSystemObject")
objFS.CreateFolder""& objFDD &""

'■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
' Step2 イベントログのバックアップ及び削除
'■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■

strComputer = "."
set objComputer = WScript.CreateObject("WScript.Network")
Set objWMIServiceA = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Backup)}!\\" & _
strComputer & "\root\cimv2")
Set objWMIServiceB = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Backup)}!\\" & _
strComputer & "\root\cimv2")
Set objWMIServiceC = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Backup,Security)}!\\" & _
strComputer & "\root\cimv2")

Set colLogFilesA = objWMIServiceA.ExecQuery _
("Select * from Win32_NTEventLogFile where LogFileName='Application'")
For Each objLogfileA in colLogFilesA
errBackupLogA = objLogFileA.BackupEventLog(""& objFDD &"\"& objComputer.ComputerName &"-application.evt")
If errBackupLogA <> 0 Then
Wscript.Echo "The Application event log could not be backed up."
Else
objLogFileA.ClearEventLog()
End If
Next
Set colLogFilesB = objWMIServiceB.ExecQuery _
("Select * from Win32_NTEventLogFile where LogFileName='System'")
For Each objLogfileB in colLogFilesB

errBackupLogB = objLogFileB.BackupEventLog(""& objFDD &"\"& objComputer.ComputerName &"-System.evt")
If errBackupLogB <> 0 Then
Wscript.Echo "The System event log could not be backed up."
Else
objLogFileB.ClearEventLog()
End If
Next
Set colLogFilesC = objWMIServiceC.ExecQuery _
("Select * from Win32_NTEventLogFile where LogFileName='Security'")
For Each objLogfileC in colLogFilesC
errBackupLogC = objLogFileC.BackupEventLog(""& objFDD &"\"& objComputer.ComputerName &"-Security.evt")
If errBackupLogC <> 0 Then
Wscript.Echo "The Security event log could not be backed up."
Else
objLogFileC.ClearEventLog()
End If
Next

                                                                                                                                                                        • -