tags:

views:

30

answers:

1

I have a batch file that runs a richcopy program, I am wanting to monitor the errorlevel so far i have got this

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

:Report

:OK END

What I am wanting to do is to report the error to the event viewer so that it can be monitored via another application that monitors the event logs.

+2  A: 

You can use EVENTCREATE to write to the event log.

An example would be:

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

More information can be found at the TechNet article.

EDIT

In your case, try this. Your parenthesis and use of == may be throwing things off.

@ECHO OFF

IF %ERRORLEVEL% NEQ 3010 goto OK    

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

:OK 

EXIT

This way, if the error level isn't 3010, it always skips to the OK method, in case you get something other than 0 or 3010.

LittleBobbyTables
Thats great but it reports every time to the event viewer even on success?
andy
Revised my answer based on the event always firing
LittleBobbyTables