How to send an email on event (with event details) in Windows 7

4

2

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.

kurochenko

Posted 2012-02-12T22:39:41.350

Reputation: 143

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.

– Ƭᴇcʜιᴇ007 – 2012-02-12T23:22:19.720

@techie007 thanks for reply. I've updated question – kurochenko – 2012-02-12T23:41:54.627

So all you want is an email when someone logs on? Do you need to know who logged on or anything like that? – Ƭᴇcʜιᴇ007 – 2012-02-12T23:44:27.027

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. – edusysadmin – 2012-02-12T23:46:25.650

@techie007 yes, email with event message which can be seen in Event Viewer – kurochenko – 2012-02-12T23:46:57.367

Answers

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

jdh

Posted 2012-02-12T22:39:41.350

Reputation: 6 645

1And how do i get event message to emails body? – kurochenko – 2012-02-13T08:49:47.833

(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 – 2012-02-13T16:41:57.573

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 - http://blogs.technet.com/b/otto/archive/2007/11/09/find-the-event-that-triggered-your-task.aspx

– jdh – 2012-02-13T16:46:42.887

1

user290259

Posted 2012-02-12T22:39:41.350

Reputation: 11

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. – r03 – 2016-06-20T08:21:10.253

1Can you please share actual solution instead of just posting a link? – Martin Prikryl – 2014-01-15T15:05:55.070

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/

Vijred

Posted 2012-02-12T22:39:41.350

Reputation: 11

1Need more than a link. Expand to show the solution other wise this is a trite answer and the link may eventualy break. – Carl B – 2014-03-21T07:47:47.583

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.

rpet

Posted 2012-02-12T22:39:41.350

Reputation: 21