Batch file to write to Event Viewer

I have a batch file that runs the richcopy program, I want to track the level of errors so far, I have this

IF (% ERRORLEVEL% == 0) goto OK else IF (% ERRORLEVEL% == 3010) goto Report

: Report

: OK END

What I want to do is report the error to the event viewer so that it can be tracked through another application that tracks event logs.

+7
copy batch-file
source share
1 answer

You can use EVENTCREATE to write to the event log.

Example:

 EVENTCREATE /T ERROR /L APPLICATION /ID 100 /D "This is your error message." 

More information can be found in the TechNet article .

EDIT

In your case, try this. Your bracket and using == can throw things away.

 @ECHO OFF IF %ERRORLEVEL% NEQ 3010 goto OK EVENTCREATE /T ERROR /L APPLICATION /ID 100 /D "This is your error message." :OK EXIT 

Thus, if the error level is not equal to 3010, it always skips the OK method if you get something other than 0 or 3010.

+16
source share

All Articles