Microsoft KB Archive/257541

= How to write to the Application log in Windows NT, Windows 2000, or Windows XP using the Windows Script Host =

Article ID: 257541

Article Last Modified on 8/27/2007

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 7.0 Professional Edition
 * Microsoft Visual FoxPro 8.0 Professional Edition
 * Microsoft Visual FoxPro 9.0 Professional Edition

-



This article was previously published under Q257541



SUMMARY
The Microsoft Script Host makes it easy to write to the application event log of Microsoft Windows NT 4.0, Windows 2000, Windows XP, or later versions of Windows. The Event Viewer is used to view and to manage logs of system, program, and security events on computers that are running Windows NT 4.0 or later versions of Windows. You can use the event logs in Event Viewer to gather information about hardware, software, and system problems, and to monitor Windows security events.



MORE INFORMATION
Windows records events in three kinds of logs in Windows NT 4.0, Windows 2000, Windows XP, and later versions of Windows:
 * Application log

The application log contains events logged by applications or programs. For example, a database program might record a file error in the application log. The developer decides which events to record.
 * System log

The system log contains events logged by the Windows NT 4.0, Windows 2000, and Windows XP and later system components. For example, the failure of a driver or other system component to load during startup is recorded in the system log. The event types logged by system components are predetermined.
 * Security log

The security log can record security events such as valid and invalid logon attempts, as well as events related to resource use, such as creating, opening, or deleting files. An administrator can specify what events are recorded in the security log. For example, if you have enabled logon auditing, attempts to log on to the system are recorded in the security log.

Event Viewer displays these types of events:
 * Error

A significant problem, such as loss of data or loss of functionality. For example, if a service fails to load during startup, an error is logged.
 * Warning

An event that is not necessarily significant, but might indicate a possible future problem. For example, when disk space is low, a warning is logged.
 * Information

An event that describes the successful operation of an application, driver, or service. For example, when a network driver loads successfully, an information event is logged.
 * Success audit

An audited security access attempt that succeeds. For example, a user's successful attempt to log on to the system is logged as a success audit event.
 * Failure audit

An audited security access attempt that fails. For example, if a user tries to access a network drive and fails, the attempt is logged as a failure audit event.

The event log service starts automatically when you start Windows NT 4.0, Windows 2000, Windows XP, and later versions of Windows. Application and system logs can be viewed by all users, but security logs are accessible only to administrators.

The following code demonstrates how to use the Windows Script Host to write to the application log in Windows NT 4.0, Windows 2000, or later versions of Windows. If you are using this code on Windows 95 or Windows 98, it will write to Wsh.log in the user's Windows directory. The Wsh.log file contains a time stamp, the event type, and the text of the log entry.

The LogEvent method uses the following syntax:

LogEvent(intType, strMessage)

where:

intType is a number representing the type of the event.

strMessage is the text of the log entry.



WshShell = CreateObject("WScript.Shell") ?WshShell.LogEvent(SUCCESS, "Logon Script Completed Successfully") WshShell.LogEvent(ERROR, "Logon Script Completed Successfully") WshShell.LogEvent(WARNING, "We are getting low on disk space!!") WshShell.LogEvent(INFORMATION, "Start nightly backup") WshShell.LogEvent(AUDIT_SUCCESS, "Checksum Success!!") WshShell.LogEvent(AUDIT_FAILURE, "Checksum Failure")
 * 1) DEFINE SUCCESS 0
 * 2) DEFINE ERROR 1
 * 3) DEFINE WARNING 2
 * 4) DEFINE INFORMATION 4
 * 5) DEFINE AUDIT_SUCCESS 8
 * 6) DEFINE AUDIT_FAILURE 16
 * !* Logevent returns .t. for SUCCESS for .f. for FAILURE

WshShell=.NULL.

