We currently have a Windows Server 2008 machine that we have configured with a Custom Task to send an email whenever an error occurs in a certain Event Log. The trigger works perfectly, and sends emails whenever we need them to.

HOWEVER, we cannot find a way to get the email to contain information about the error, particularly the error message. Is there any way to have the message change based on the contents of the event-log error?


Maybe eventtriggers is your answer? I'm not too familiar with Server 2008 yet but I used to use eventtriggers all the time with 2003. Let's you do whatever you want since you can run any command or script you write.




Use eventtriggers to trigger a VBscript to run. You can use a script like the following to send email with the recent errors, but I have not put this into production yet because it causes high CPU usage on the server in WMIPRVSE.EXE (I'm assuming this is the process that handles WMI queries).

WARNING: Following script causes high CPU usage and isn't ready for high usage/mission critical systems

strComputer = "."

Dim emailText
emailText = "An error has occurred on [server_name]. This email was generated by eventtriggers.exe on [server_name]. Run eventtriggers.exe /? at the command prompt on [server_name] for help with managing event triggers." & vbNewLine & vbNewLine & "Recent Errors:" & vbCrLf

Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" _
  & strComputer & "\root\cimv2")

Set colLoggedEvents = objWMIService.ExecQuery _
  ("Select * from Win32_NTLogEvent " _
    & "Where Type = 'Error'")

Dim count

For Each objEvent in colLoggedEvents
  emailText = emailText & "*****************************************************************************" & vbNewLine & vbNewLine & objEvent.Message & vbNewLine & vbNewLine
  count = count + 1
  If count > 4 then
    Exit For
  End If

Set objEmail = CreateObject("CDO.Message")
objEmail.From = "server@company.com"
objEmail.To = "name@company.com"
objEmail.Subject = "Server Error"
objEmail.Textbody = emailText
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

Alternatively, check out this answer: Windows Event Log - email notification

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy