Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch File to write to event viewer

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.

like image 937
andy Avatar asked Aug 19 '10 15:08

andy


1 Answers

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.

like image 163
LittleBobbyTables - Au Revoir Avatar answered Sep 28 '22 06:09

LittleBobbyTables - Au Revoir