bbaski has asked for the wisdom of the Perl Monks concerning the following question:

Hi
I am trying to write an entery in EventLog. But I am write it.
Can anyone help me ?
use Win32::EventLog;

$handle=Win32::EventLog->new("Security", $ENV{ComputerName}) or die "Can't open Application EventLog\n";
%eventinfo=();
$eventinfo{'Event Type'}=EVENTLOG_AUDIT_FAILURE;
$eventinfo{'Category'}="Login";
$eventinfo{'Event ID'}=5;
$eventinfo{'Data'}="Some dummy data";
$eventinfo{'Strings'}="This is event is generated by a Test Script";
$handle->Report(\%eventinfo);
Let me know whats wrong in this ...

Replies are listed 'Best First'.
Re: Writing to Event Log (Security)
by marto (Cardinal) on Mar 17, 2009 at 11:15 UTC

    What happens when you run your code, an error/warning message?

    #!/usr/bin/perl use strict; use warnings; use Win32::EventLog; my $handle = Win32::EventLog->new("Application") or die "Can't open Ap +plication EventLog\n"; my $Event = { EventType => EVENTLOG_AUDIT_FAILURE, Category => 'Login', EventID => 5, Data => "Some dummy data", Strings => "This is event is generated by a Test Script", }; $handle->Report($Event);

    The above code works for me.

    Martin

      I am using new("Security") instead of new("Application")
      Eg:
      my $handle = Win32::EventLog->new("Security") or die "Can't open Application EventLog\n";
      The script run without error
      But i dont see any entry under Security


      Waiting for hopefully...
Re: Writing to Event Log (Security)
by frieduck (Hermit) on Mar 17, 2009 at 21:11 UTC
    Do you know if you (your program) has permissions to write to the Security event log? This article seems to indicate that the default is that you would not. In fact, if I read that article correctly, you will not be able to use the regular event APIs (what Win32::EventLog uses) to write to the Security event log at all on XP/2003 and higher, regardless of permissions.

      Thanks...guys... Problem is with permissions. The acrticle said above clearly says what are the permissions required and api which required to wirte to security log.

      Thanks