Ramblings From The Litter Tray of Life

Posts Tagged ‘bat’

Generating an event log with a batch script

Posted by graycat on 20 May 2008

It’s not something I’ve ever really had to do before but as part of some troubleshooting today I needed to prove a script was not only running but connecting to a remote executable. My plan was to add a local entry into the event log and then echo the username, date and time to a centralised log file alongside the remote executable.

The first part was remarkably easy to achieve! Unbeknownst to me there is an executable under %windir%\system32 called eventcreate.exe …. which does exactly what is says on the tin, namely create an event in the event log. A few switches are all you need to specify event type (error, info, warning), ID number (anything from 1 – 1000) and the information included.

Here’s what I went with:

%windir%\system32\eventcreate.exe /T INFORMATION /ID 666 /D “SCRIPT RAN LOCALLY”

Told you it was easy!

Slapping the username, date and time into the remote log file was just a case of using the following:

echo %username% %date% %time% >> \\remote\log\file.txt

And now hopefully there’s going to be a local event and a remote log file to help me sort this darn issue out!

Only time will tell but I’ll keep in touch.

Posted in Applications, IT | Tagged: , , , | Leave a Comment »