Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - Error Trapping and Capturing Third-Party O...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Error Trapping and Capturing Third-Party Output in WSH
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2007-03-05

    Table of Contents:
  • Error Trapping and Capturing Third-Party Output in WSH
  • Trapping Errors
  • Logging to the Event Log
  • Capturing Third-Party Output

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Error Trapping and Capturing Third-Party Output in WSH - Logging to the Event Log


    (Page 3 of 4 )

    Logging to a simple log file may not always be enough.  If you were performing system processes or automating applications you may wish to keep an error record in the actual Windows Event Log.

    Value

    Event Type

    0

    SUCCESS

    1

    ERROR

    2

    WARNING

    4

    INFORMATION

    8

    AUDIT_SUCCESS

    16

    AUDIT_FAILURE

    Luckily, WSH provides an easy way for us to do that as well.  The WshShell object has a LogEvent method that allows us to record our events in the Application Event Log.

    The LogEvent method can log to either the local computer or to a remote system.  This is nice if you are monitoring several different machines at the same time from one location such as a server.  Keep in mind also that event logging is always enabled on any Microsoft Windows system.

    object.LogEvent value, string[, computername]

    The LogEvent method accepts two required attributes.  The first is the numerical value for the Event Type.  You can find the list of possible values in the table above.  The second attribute is the text string that contains the description for the event.  A third optional attribute is used to specify the name of a remote computer to log the event to.

    Set objShell = WScript.CreateObject("Wscript.Shell")

     

    objShell.LogEvent 0,"Test Success Event"

    objShell.LogEvent 1,"Test Error Event"

    objShell.LogEvent 2,"Test Warning Event"

    objShell.LogEvent 4, "Test Information Event"

    objShell.LogEvent 8, "Test Success Audit Event"

    objShell.LogEvent 16, "Test Failure Audit Event"

    The above code will log one of each of the event types to the Applications Event Log.  You can verify this by clicking start, Run…, and typing eventvwr.msc in the Run dialog box to start the system's Event Viewer.  Select Application in the left pane to view the Application log.

    All events logged in this manner will have the Source “WSH” for Windows Script Host.  The Event ID will match the Event Type provided.

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · Hey, guys. In this article I'm wrapping up my logging concept by showing you how to...
     

    WINDOWS SCRIPTING ARTICLES

    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT