General
cancel
Showing results for 
Search instead for 
Did you mean: 

Write to EventLog (lotsof points !!!)

SOLVED
Go to solution
Georg Tresselt
Honored Contributor

Write to EventLog (lotsof points !!!)

Hello experts,

I'm working on script which I want to write a message to the Windows EventLog when it runs into a serious error. Is there any utility to do that, maybe in the resource kit ? Or is there a way to do it in perl. The Win32::EventLog only allows to read the Log.

Merry Xmas
http://www.tresselt.eu
10 REPLIES
Gary Cooper_1
Esteemed Contributor

Re: Write to EventLog (lotsof points !!!)

Georg Tresselt
Honored Contributor

Re: Write to EventLog (lotsof points !!!)

Isn't there something similar to the logger command on UNIX ? Thought I had seen something like that in the past.
http://www.tresselt.eu
Gary Cooper_1
Esteemed Contributor
Solution

Re: Write to EventLog (lotsof points !!!)

Georg Tresselt
Honored Contributor

Re: Write to EventLog (lotsof points !!!)

Regarding perl, as I said already Win32::EventLog doesn't write to the EventLog. But could there be a way to do it with Win32::OLE ???
http://www.tresselt.eu
Ganesh Babu
Honored Contributor

Re: Write to EventLog (lotsof points !!!)

Georg Tresselt
Honored Contributor

Re: Write to EventLog (lotsof points !!!)

Thanks Ganesh,

But if you look closely you'll see that Gary had posted that one already. Maybe, I read it a bit in a hurry, but I don't see how I could write directly with Perl to the Windows EventLog.

I've now implemented a system call to logevent, works fine.

Cheers
Georg
http://www.tresselt.eu
Ganesh Babu
Honored Contributor

Re: Write to EventLog (lotsof points !!!)

This is the code Gary has written in the query.pl file he had in the zip file..

use vars qw( %Log );
use strict;
use Win32::EventLog;

my %EVENT_TYPES = (
error => EVENTLOG_ERROR_TYPE,
warning => EVENTLOG_WARNING_TYPE,
info => EVENTLOG_INFORMATION_TYPE,
success => EVENTLOG_AUDIT_SUCCESS,
failure => EVENTLOG_AUDIT_FAILURE
);

foreach my $Key ( qw( Computer
Source
EventType
EventID ) )
{
$Log{$Key} = shift @ARGV;
}
$Log{Strings} = join( "\0", @ARGV );
if( my $Event = Win32::EventLog->new( $Log{Source}, $Log{Computer} ) )
{
$Log{EventType} = $EVENT_TYPES{$Log{EventType}};
if( $Event->Report( \%Log ) )
{
print "Log was successfully sent.\n";
}
else
{
print "Unable to submit log.\n";
}
$Event->Close();
}
else
{
print "Unable to connect to $Log{Computer}.\n";
}

Ganesh

lowster
Honored Contributor

Re: Write to EventLog (lotsof points !!!)

\\computername-s severity-c categorynumber-r source-e eventID-t timeout"event text"
Georg Tresselt
Honored Contributor

Re: Write to EventLog (lotsof points !!!)

Hi Ganesh,

Call me stupid (you probably do) but I don't see anything in that code that writes to the EventLog. I guess that's why the script is called query.pl

But, don't mind. I needed it only for some exeptionnal error handling and a system call with logevent does the job nicely.

Thanx
Georg
http://www.tresselt.eu
Jon Finley
Honored Contributor

Re: Write to EventLog (lotsof points !!!)

From Gary Cooper's first post, the second link go to page 3.
http://www.windowsitpro.com/WindowsScripting/Articles/ArticleID/16404/pg/3/3.html

WriteEventLog() is the function discussed.

Jon
"Do or do not. There is no try!" - Yoda