Reporting erros in batch files to the Event Log

U

urs

I'm running a *.BAT file via Task Scheduler every 20 minutes. The batch
file does some file copies to a backup server.

The problem is, if a copy ends with errors, I won't get notified. What
I would like is the batch file to report any errors to the Event Log.
Is there a way to write to the event log from a batch file? Or can the
Task Scheduler be told to write any errors to the event log?

Thanks for any help
Urs
 
P

Pegasus \(MVP\)

I'm running a *.BAT file via Task Scheduler every 20 minutes. The batch
file does some file copies to a backup server.

The problem is, if a copy ends with errors, I won't get notified. What
I would like is the batch file to report any errors to the Event Log.
Is there a way to write to the event log from a batch file? Or can the
Task Scheduler be told to write any errors to the event log?

Thanks for any help
Urs

You could do it like this:

@echo off
c:\tools\SomeTask.exe || logevent.exe /switches

logevent.exe comes with the Windows Resource Kit.
 
U

urs

Hi Pegasus, thanks for the tip with logevent.exe. However, it doesn't
work. I use the command
copy c:\a.txt c:\b.txt || logevent.exe /s W /e 0

but there would just an useless message being logged in the event log
which reads
Event Type: Information
Event Source: User Event
Event Category: None
Event ID: 1
Date: 16.02.2006
Time: 15:48:30
User: N/A
Computer: SN015D
Description:
The description for Event ID ( 1 ) in Source ( User Event ) cannot be
found. The local computer may not have the necessary registry
information or message DLL files to display messages from a remote
computer. You may be able to use the /AUXSOURCE= flag to retrieve this
description; see Help and Support for details. The following
information is part of the event: /s.


seems like logevent doesn't take parameters from the || ? also, /s and
/e don't seem to be recognized, so I also tried -s W -e 0 (as in the
help text). But these switchers don't get recognized either...

do you know what I'm doing wrong here?
Urs
 
U

urs

of course I saw this too, but it doesn't tell me how to log arbitrary
error messages which come from a command to the event log.
 
P

Pegasus \(MVP\)

of course I saw this too, but it doesn't tell me how to log arbitrary
error messages which come from a command to the event log.

If course it does - your own message is right at the
end of the event logger entry. Muesch nume guet luege!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top