Windows Scripting
  Home arrow Windows Scripting arrow Logging Events in WSH
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 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
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

Logging Events in WSH
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-02-26

    Table of Contents:
  • Logging Events in WSH
  • Providing the Right Information
  • Constructing the Subroutines
  • Incorporating Logging into Your Script

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Logging Events in WSH


    (Page 1 of 4 )

    As you advance in your abilities to work with WSH you will find yourself writing more detailed and intricate code. Many of these scripts will be system administration scripts designed to run in the background. Thus, it can be very useful for your script to generate an event log.

    Logging can be a highly detailed process.  You may want to log the events that occur as your script runs; you may also want to log any errors that are encountered.  These topics stretch far beyond the scope of a single article or series so I’ll only be giving you some basic techniques.  It will be up to you to develop them for use in your own situation and for your own scripting style.

    The most common method of logging is to a plain text file so we will be concentrating on that.  The techniques would be similar if you wanted to log to a different type of file or even to a database.  For lack of space, I’m not going into detail on how to manage the log file.  Please take the time to read my “Reading Text Files in WSH” and “Writing Text Files in WSH” articles for more information.

    The code samples in this article use predefined subroutines that I have created and made available for download.  You can use or modify these scripts any way you like.  Once you modify them to your liking, I suggest packaging them as a class so that you can reuse them in all of your scripts.

    Basically, we need to accomplish a few basic steps in our script:

    1. Identify an action taking place.
    2. Determine if that action results in an error.  If so,
    3. Make an entry for that error in our log file.

    Each event will appear on its own line in our log file.  A simple logging script might look like this:

    Const logfile = "C:log.txt"

    Set objFso = CreateObject("Scripting.FileSystemObject")

    Set objLog = objFso.CreateTextFile(logfile, True)

     

    objLog.WriteLine "Logging Started "

    objLog.WriteLine "Logging Ended "

    In this example, all we’ve done is created a text file and written a few lines to it.  This isn’t doing much good at this point.  Trust me, it will all come together.  The log.txt will look something like this.

    Logging Started

    Logging Ended

    Okay, so this log file is a bit vague.  We need to add some more information to this log if it’s going to be at all useful.

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


       · Add a whole new dimension of power and a level of professionalism to your scripts by...
     

    WINDOWS SCRIPTING ARTICLES

    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications
    - Securing Computers and Active Directory
    - Moving and Renaming Computers with Active Di...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway