4

How do I send an email with event details when some event occurs in Windows 7, for example when any user logs on?

I've tried to use Event Viewer, but I haven't found out how to attach event details to the email's body.

5
  • It's not very straight-forward, and would depend on the specific 'details' you wish to gather, and for which event(s). Perhaps edit your question and provide those specifics? There's good info/tutorial on it here on Technet. Feb 12, 2012 at 23:22
  • @techie007 thanks for reply. I've updated question
    – kurochenko
    Feb 12, 2012 at 23:41
  • So all you want is an email when someone logs on? Do you need to know who logged on or anything like that? Feb 12, 2012 at 23:44
  • Is there a specific event log entry you are attemping to base this off of? I'd use a different approach, create a Task that is triggered by login that runs a script to get current user and then email it. Such a script is pretty straight forward in PS. Feb 12, 2012 at 23:46
  • @techie007 yes, email with event message which can be seen in Event Viewer
    – kurochenko
    Feb 12, 2012 at 23:46

4 Answers 4

5

Use the task scheduler from the (Control Panel -> Administrator's Tools). It has the option to run a script, program or action, depending on some trigger (like someone logging on, running a program etc) Here's an example setup dialog (you are interested in the event "at log on") : enter image description here

3
  • 1
    And how do i get event message to emails body?
    – kurochenko
    Feb 13, 2012 at 8:49
  • (First, in addition to manually creating the task above, you can more easily setup the task thru the event log. Find Event 4624 and pick "Attach taqsk to this Event..".)
    – jdh
    Feb 13, 2012 at 16:41
  • 1
    Then the task needs to be exported (to an XML file), edited to include event fields and then imported back into the task scheduler as a new event. Here's an example of someone doing something similar - blogs.technet.com/b/otto/archive/2007/11/09/…
    – jdh
    Feb 13, 2012 at 16:46
1

This seems simpler if you want the event text too

http://blogs.technet.com/b/jhoward/archive/2010/06/16/getting-event-log-contents-by-email-on-an-event-log-trigger.aspx

2
  • 1
    Can you please share actual solution instead of just posting a link? Jan 15, 2014 at 15:05
  • On an event is the option "Attach Task To This Event", here you can select an email action. If you want an attachment you can generate a file with a previous action and use that as attachment.
    – roeland
    Jun 20, 2016 at 8:21
1

You need to export the job, edit XML file of the task and add value to ValueQueries. Import the job again and edit mail details. You can include Event Details and any information in the event.

Below article explains step by step on how to do the same: http://vijredblog.wordpress.com/2014/03/21/task-scheduler-event-log-trigger-include-event-data-in-mail/

1
  • 1
    Need more than a link. Expand to show the solution other wise this is a trite answer and the link may eventualy break.
    – Carl B
    Mar 21, 2014 at 7:47
0
  1. Export the job from the task scheduler
  2. Edit the XML file of the task, add a ValueQueries node inside . Add value nodes inside it. For example: <EventTrigger> ... <ValueQueries> <Value name="EventData">Event/EventData/Data</Value> </ValueQueries> ... </EventTrigger>
  3. Import the job again and edit mail details. You can use $(EventData) to include the event details

Please note that not all Windows Server versions admit this XML schema, but I guess that any recent version (WS2012 onwards) will be fine. For example: WS2008 (non R2), which uses http://schemas.microsoft.com/windows/2004/02/mit/task schema, does not like it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .