Create Custom Events with a Single Command

With the Eventcreate command, you can have your scripts, applications, and other components log custom events.

Apostolos Fotakelis

August 29, 2007

2 Min Read
ITPro Today logo in a gray background | ITPro Today


The Windows Event Viewer is a toolthat can provide you with useful information regarding your computer'shealth. It contains at least three logs:the Application log (which containsevents generated by applications), the Security log (which containssecurity-related events generated byWindows), and the System log (whichcontains system-wide events generatedby Windows). Each log displays Information, Warning, and Error events,which are accompanied by the nameof the source component that raisedthe event, a brief event description,and an event ID. Administrators relyon these logs not only for informationabout problems (e.g., failure to start a service) but also for informationabout successful operations (e.g., successful RAS connections).

Sometimes it's useful to log yourown events. For example, I have astartup script that I've scheduled torun every night. I recently found away to log its events so that I couldmake sure it was successfully executing. You can log events by using theEventcreate command. The basicsyntax that I use is:

Eventcreate /ID EventID   /L LogName /T Type /SO Source /D Description 

where

  • EventID is the ID you want to give the event. You can use any number from 1 to 1000.

  • LogName is the name of the log to which you want to write the event. You can write to the Application or System log but not the Security log.

  • Type defines the severity of the event. You can specify Information, Warning, or Error.

  • Source specifies the component (e.g., application, script) generating the event.

  • Description is the text you want displayed when the event appears in the log.

For example, I created the following event to be logged whenever mystartup script successfully executes.Note that this command has to beentered inside the startup script:

Eventcreate /ID 123   /L Application /T Information  /SO StartupScript /D "Startup script executed!"

You can even write events to a logon another computer by using theeventcreate command's /S Computerparameter (where Computer is themachine's name). If you need tospecify alternate credentials for the remote-computer, you can use the /U User and /P Password parameters (where User andPassword are the credentials). For information about these three parameters, open a command prompt and type

eventcreate /? 

The Eventcreatecommand works onWindows Server 2003and Windows XP. Ihaven't tested it on anyother OSs.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like