Code: Select all
//Config
Let>LogFile=System
//Event code 6008 is "Unexpected Shutdowns"
Let>EventCode=6008
Let>iniFile=%SCRIPT_DIR%\EventMonitor.ini
Let>mailserver=mail.host.com
Let>[email protected]
VBSTART
Function ReadEventLog(LogFile,Code)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery ("Select * from Win32_NTLogEvent Where Logfile = '" & LogFile & "' and EventCode = '" & Code & "'")
ReadEventLog = colLoggedEvents.Count
End Function
VBEND
//Get current event count
VBEval>ReadEventLog("%LogFile%","%EventCode%"),locCount
//Get stored value from ini file
IfFileExists>iniFile
ReadIniFile>iniFile,LogFile,EventCode,storeCount
If>storeCount>locCount
Let>newCount=locCount-storeCount
SMTPSendMail>recipient,mailserver,[email protected],Event Monitor,Event %EventCode% Detected,%newCount% Events of Type %EventCode% Detected in log: %LogFile%
Endif
Else
//first time we've run, create INI file
WriteLn>iniFile,r,
Endif
//Store current count
EditIniFile>iniFile,LogFile,EventCode,locCount
Schedule the script to run at the required intervals. Use different versions of the script for different event types (or consider modularising with the Include statement to avoid duplication).
The script could be modified to pop up a message box instead/as well as send an email, or run another script or application ... or do whatever is required.