Option Explicit ' 変数、定数の定義 Const cdoSendUsingMethod = _ "http://schemas.microsoft.com/cdo/configuration/sendusing" Const cdoSendUsingPort = 2 Const cdoSMTPServer = _ "http://schemas.microsoft.com/cdo/configuration/smtpserver" Const cdoSMTPServerPort = _ "http://schemas.microsoft.com/cdo/configuration/smtpserverport" Const cdoSMTPConnectionTimeout = _ "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout" Const cdoSMTPAuthenticate = _ "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate" Const cdoBasic = 1 Const cdoSendUserName = _ "http://schemas.microsoft.com/cdo/configuration/sendusername" Const cdoSendPassword = _ "http://schemas.microsoft.com/cdo/configuration/sendpassword" 'boosterには送信に使う SMTP サーバの IP アドレスか FQDN を指定する Const booster = "XXX.XXX.XXX.XXX" Dim WshShell, env, events, NTEvent, objConfig, Fields, objMessage, subj ' WMIを通じて抽出するイベントの条件指定 'Set WshShell = WScript.CreateObject("WScript.Shell") 'set env = WshShell.Environment("SYSTEM") Set events = GetObject("winmgmts:{impersonationLevel=impersonate,(security)}") _ .ExecNotificationQuery("SELECT * FROM " & _ "__instancecreationevent WHERE " & _ "targetinstance isa 'Win32_NTLogEvent' " & _ "and targetInstance.EventIdentifier= '529' " ) ' 指定されたイベントの発生に伴い実行するアクションの指定 if err <> 0 then WScript.Echo Err.Description, Err.Number, Err.Source end if Do 'CDOメッセージの作成 Set NTEvent = events.NextEvent subj ="[Notice] ログオンの失敗発生: " & NTEvent.TargetInstance.ComputerName Set objConfig = CreateObject("CDO.Configuration") Set Fields = objConfig.Fields With Fields .Item(cdoSendUsingMethod) = cdoSendUsingPort .Item(cdoSMTPServer) = booster .Item(cdoSMTPServerPort) = 25 .Item(cdoSMTPConnectionTimeout) = 10 .Item(cdoSMTPAuthenticate) = cdoBasic .Item(cdoSendUserName) = "username" .Item(cdoSendPassword) = "password" .Update End With Set objMessage = CreateObject("CDO.Message") Set objMessage.Configuration = objConfig With objMessage .To = "あて名 <あて先メールアドレス>" .From = "差出人 <差出人メールアドレス>" .Subject =subj .TextBody ="サーバ " & NTEvent.TargetInstance.ComputerName & " で、標記のイベントが発生しました。" &vbCRLF & "即刻、詳細を確認願います。" &vbCRLF &vbCRLF &"検知時刻: "& Now() &vbCRLF &vbCRLF & "[イベント詳細] " &vbCRLF &vbCRLF & NTEvent.TargetInstance.message .Send End With ' メッセージ送信後、利用したオブジェクトをクリアする Set Fields = Nothing Set objMessage = Nothing ' 処理完了後は次のイベントに備え、LoopによりDoループの先頭に戻る Loop