Hi,

Is the script below correct?  It works as expected, except I get the error:
Use of uninitialized value in unpack at
C:/Perl/site/lib/Win32/EventLog.pm line 130.
It seems to be trying to read an event after the last has been read.

Either I have done something wrong, or Win32::EventLog should do:

sub Read {
    my $self = shift;

    die "usage: OBJECT->Read(FLAGS, RECORDOFFSET, HASHREF)\n" unless @_ == 3;

    my ($readflags,$recordoffset) = @_;
    # The following is stolen shamelessly from Wyt's tests for the registry.
    my $result = ReadEventLog($self->{handle}, $readflags, $recordoffset,
                              my $header, my $source, my $computer, my $sid,
                              my $data, my $strings);
    # insert this
    if ($result) {
        my ($length,
        $reserved,
        $recordnumber,
        .... continue with rest of code
    }

    return $result;
}

Any info would be great.

Thanks,
Mike


My test script:

use strict;

use Win32::EventLog;

foreach my $event_log (qw(application system security)) {
    my $handle;
    my $hashRef;
    my $oldest;
    my $number;
    if (!($handle = Win32::EventLog->new($event_log, $ENV{ComputerName}))) {
        print "Could not open $event_log\n";
        next;
    }
    
    if (!$handle->GetOldest($oldest)) {
        print "Could not get oldest from $event_log\n";
        next;
    }
    
    if (!$handle->GetNumber($number)) {
        print "Could not get number of recs from $event_log\n";
        next;
    }
    # if there is nothing to read,
    if ($number == 0) {
        next;
    }
    
    if ($handle->Read(EVENTLOG_BACKWARDS_READ|EVENTLOG_SEEK_READ,
$oldest, $hashRef)) {
        while ($handle->Read(EVENTLOG_FORWARDS_READ|EVENTLOG_SEQUENTIAL_READ,
0, $hashRef)) {
            print $hashRef->{Strings}, "\n";
        }
    }
}

_______________________________________________
Perl-Win32-Admin mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to