Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

September 26, 2008 12:00 AM

Mimic Vista's Event Triggers in XP

Receive email notifications when specific events occur
Windows IT Pro
InstantDoc ID #99979
Rating: (5)
Downloads
99979.zip

Some of our customers have started migrating their client OSs from Windows XP to Windows Vista. They’re pretty impressed by the Vista features that simplify their administrative workloads. One such feature is the Event Viewer’s Attach Task To This Event option, which lets you create an event-triggered action, such as sending an email notification when a specific event occurs. (To access this option, type Event Viewer in the Start menu’s search box, and click the Event Viewer icon that appears under the Programs heading. In Event Viewer, double-click an event ID in the Summary of Administrative Events box to bring up the Attach Task To This Event option in the Actions pane.)

Once customers get a taste of using event-triggered actions in Vista, they often ask how they can create them on the remaining XP workstations in their domains without having to use third-party software. I provide them with a relatively simple solution that uses a VBScript script and eventtriggers.exe, a command-line utility included in Windows Server 2003 and XP. (Eventtriggers.exe isn’t included in Windows 2000 and won’t run if you copy it to Win2K. Vista doesn’t include this utility because the Attach Task to this Event feature makes it unnecessary.)

The solution is as follows:

1. Launch Notepad and enter the script in Listing 1, replacing all the string values in double quotes with your own information. (Leave in the double quotes.) You can download this script by going to www.windowsitpro.com, entering 99979 in the InstantDoc ID box, clicking Go, then clicking the Download the Code Here button.
2. Save the script as Email.vbs.
3. Copy the Email.vbs script to the XP workstation. For this example, let’s put it in the C:\utils folder.
4. On the XP workstation, launch a command-prompt window and enter the command

Eventtriggers /Create
  /TR "Event Triggers for All Errors"
  /T ERROR /TK C:\utils\email.vbs
(Although this command appears on several lines here, you’d enter it all on one line in the command-prompt window.) In this command, the /TR parameter provides the trigger’s name (Event Triggers for All Errors), the /T parameter specifies the type of event that the trigger should capture (ERROR events), and the /TK parameter identifies the trigger action (execute Email.vbs).

When an error appears in any log file on that workstation, Email.vbs is executed and sends an email notification to the recipient designated in the script. You can fine-tune the Eventtriggers command using its many parameters to capture specific events based on the event ID. For a list of the available parameters, run the command

Eventtriggers /Create /?
in a command-prompt window.

—Jian Bo

Related Content:

ARTICLE TOOLS

Comments
  • Bret
    3 years ago
    Oct 30, 2009

    Hi Windows IT Pro,
    I just had an opportunity to test email.vbs: The default email program *does not* have to be running for the email to go out immediately.
    Regards,
    Bret

  • Bret
    4 years ago
    Oct 24, 2008

    Hi Jian,

    Good tool. Thanks :-)

    Question: Without my testing, does anyone know if the default email program has to be running for the email to go out immediately? Or, is the message stored in the Outbox until the next time the email program runs and does a send/receive ?

    Thanks,
    Bret

  • Fungpiew
    4 years ago
    Oct 21, 2008

    Would Eventtriggers monitor any log file instead of just the Windows Event logs?

  • Karen
    4 years ago
    Oct 08, 2008

    Hi Brian,

    I contacted Jian Bo about the error you're encountering. He recommends that you try the following code instead:

    sch = "http://schemas.microsoft.com/cdo/configuration/"
    Set cdoConfig = CreateObject("CDO.Configuration")
    With cdoConfig.Fields
    .Item(sch & "sendusing") = 2 ' cdoSendUsingPort
    .Item(sch & "smtpserver") = ""
    .update
    End With
    Set cdoMessage = CreateObject("CDO.Message")
    With cdoMessage
    Set .Configuration = cdoConfig
    .From = "from@me.com"
    .To = "to@me.com"
    .Subject = "Sample CDO Message"
    .TextBody = "This is a test for CDO.message"
    .Send
    End With
    Set cdoMessage = Nothing
    Set cdoConfig = Nothing

    In this code, you'll need to replace with your mail server. Please let me know if this works for you.

    Thanks,

    Karen Bemowski, senior editor
    Windows IT Pro, SQL Server Magazine

  • Brian
    4 years ago
    Oct 07, 2008

    Thanks for the article. I get the following error when I run the email.vbs script. Can someone recommend a fix? Thanks, Brian

    CDO.Message.1 error '80040220' The "SendUsing" configuration value is invalid.

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.