extracting event logs to a file

Discussion in 'Perl' started by Gnaneshwar Babu, Dec 31, 2003.

  1. Hi

    I am facing a problem with extracting event logs of win32 to a file.
    Am using the following code to extract eventlogs to file

    use Win32::EventLog;
    $handle=Win32::EventLog->new("System", $ENV{ComputerName})
    or die "Can't open Application EventLog\n";
    $handle->GetNumber($recs)
    or die "Can't get number of EventLog records\n";
    $handle->GetOldest($base)
    or die "Can't get number of oldest EventLog record\n";
    while ($x < $recs) {
    $handle->Read(EVENTLOG_FORWARDS_READ|EVENTLOG_SEEK_READ,
    $base+$x,
    $hashRef)
    or die "Can't read EventLog entry #$x\n";
    if ($hashRef->{Source} eq "EventLog") {
    Win32::EventLog::GetMessageText($hashRef);
    print "Entry $x: $hashRef->{Message}\n";
    }
    $x++;
    }

    from this program i used get a output as shown bellow
    ----------------------------------------------------------------
    C:\babu>perl eventlogg.pl
    Entry : The Event log service was stopped.

    Entry 1: Microsoft (R) Windows 2000 (R) 5.0 2195 Service Pack 3
    Uniprocessor Fre
    e.

    Entry 2: The Event log service was started.

    Entry 3: The Event log service was stopped.

    Entry 4: Microsoft (R) Windows 2000 (R) 5.0 2195 Service Pack 3
    Uniprocessor Fre
    e.

    Entry 5: The Event log service was started.

    Entry 6: The Event log service was stopped.

    Entry 7: Microsoft (R) Windows 2000 (R) 5.0 2195 Service Pack 3
    Uniprocessor Fre
    e.

    Entry 8: The Event log service was started.

    Entry 21: The Event log service was stopped.

    Entry 22: Microsoft (R) Windows 2000 (R) 5.0 2195 Service Pack 3
    Uniprocessor Fr
    ee.

    Entry 23: The Event log service was started.

    Entry 24: The Event log service was stopped.

    Entry 25: Microsoft (R) Windows 2000 (R) 5.0 2195 Service Pack 3
    Uniprocessor Fr
    ee.
    --------------------------------------------------------------------
    but i need a output as shown bellow

    ----------------------------------------------------------------------
    Type Date Time Source Category Event User Computer
    Information 12/31/2003 11:15:38 AM Dnsapi None 11152 N/A BDCVF-6GZR
    Information 12/31/2003 11:15:17 AM VMnetuserif None 4 N/A BDCVF-6GZR
    Information 12/31/2003 11:15:17 AM VMnetuserif None 1 N/A BDCVF-6GZR
    Information 12/31/2003 11:14:26 AM VMnetAdapter None 34 N/A BDCVF-6GZR
    Information 12/31/2003 11:14:26 AM VMnetAdapter None 34 N/A BDCVF-6GZR
    Information 12/31/2003 11:14:40 AM eventlog None 6005 N/A BDCVF-6GZR
    Information 12/31/2003 11:14:40 AM eventlog None 6009 N/A BDCVF-6GZR
    Information 12/31/2003 11:13:42 AM eventlog None 6006 N/A BDCVF-6GZR
    Warning 12/30/2003 1:40:08 PM Dnsapi None 11150 N/A BDCVF-6GZR
    Information 12/30/2003 1:40:08 PM Dnsapi None 11156 N/A BDCVF-6GZR
    Warning 12/30/2003 1:28:51 PM Dnscache None 11050 N/A BDCVF-6GZR
    Information 12/30/2003 1:22:52 PM Browser None 8033 N/A BDCVF-6GZR
    Information 12/30/2003 1:20:49 PM Dnsapi None 11152 N/A BDCVF-6GZR
    Information 12/30/2003 1:20:48 PM Dnsapi None 11152 N/A BDCVF-6GZR
    Information 12/26/2003 8:50:04 PM Application
    Popup None 26 N/A BDCVF-6GZR
    Information 12/24/2003 6:26:53 PM W32Time None 593 N/A BDCVF-6GZR
    Error 12/22/2003 11:46:41 AM VMnetDHCP None 2 N/A BDCVF-6GZR
    Information 12/22/2003 11:43:51 AM Dnsapi None 11152 N/A BDCVF-6GZR
    ---------------------------------------------------------------------------
    Please help me in getting this output....
    Thanks in adavance.
    Gnaneshwar Babu, Dec 31, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Bear

    FAQ or HOWTO on windows event logs

    David Bear, Dec 5, 2003, in forum: Python
    Replies:
    1
    Views:
    518
    Rudy Schockaert
    Dec 6, 2003
  2. Ellinghaus, Lance
    Replies:
    1
    Views:
    507
    David Bolen
    Feb 20, 2004
  3. Ron

    Vista Event Logs

    Ron, Dec 12, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    453
  4. EW
    Replies:
    2
    Views:
    544
    Mark Hammond
    Nov 25, 2009
  5. Tom G

    Web Service Accessing Remote Event Logs

    Tom G, Apr 2, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    141
    Jan Tielens
    Apr 5, 2004
Loading...

Share This Page