Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8143855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:13:27+00:00 2026-06-06T13:13:27+00:00

I am working on a program and need ot know how I would read

  • 0

I am working on a program and need ot know how I would read a specific entry to the Windows Event Log based on a Record number, which this script will already have. Below is the code I have been working with, but I don’t want to loop through all of the events until I find the one I’m looking for. Any ideas?

import win32evtlog

server = 'localhost' # name of the target computer to get event logs
logtype = 'System'
hand = win32evtlog.OpenEventLog(server,logtype)
flags = win32evtlog.EVENTLOG_BACKWARDS_READ|win32evtlog.EVENTLOG_SEQUENTIAL_READ
total = win32evtlog.GetNumberOfEventLogRecords(hand)

while True:
    events = win32evtlog.ReadEventLog(hand, flags,0)
    if events:
        for event in events:
            if event.EventID == "27035":
                print 'Event Category:', event.EventCategory
                print 'Time Generated:', event.TimeGenerated
                print 'Source Name:', event.SourceName
                print 'Event ID:', event.EventID
                print 'Event Type:', event.EventType
                data = event.StringInserts
                if data:
                    print 'Event Data:'
                    for msg in data:
                        print msg
                break
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:13:28+00:00Added an answer on June 6, 2026 at 1:13 pm

    No! There are no functions available which allows you to obtain the event based on event id.

    Reference: Event logging functions

    GetNumberOfEventLogRecords  Retrieves the number of records in the specified event log.
    GetOldestEventLogRecord     Retrieves the absolute record number of the oldest record 
                                in the specified event log.
    NotifyChangeEventLog        Enables an application to receive notification when an event
                                is written to the specified event log.
    
    ReadEventLog                Reads a whole number of entries from the specified event log.
    RegisterEventSource         Retrieves a registered handle to the specified event log.
    

    Only other method of interest is reading the oldest event.

    You will have to iterate through the results any way and your approach is correct 🙂

    You can only change the form of your approach like below but this is unnecessary.

    events = win32evtlog.ReadEventLog(hand, flags,0)
    events_list = [event for event in events if event.EventID == "27035"]
    if event_list:
        print 'Event Category:', events_list[0].EventCategory
    

    This is just the same way as you are doing but more succinct

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a class which I would like to use to log
I'm working on a program that will need to delete a folder (and then
I need to restart the program that im working on after an update has
I need to understand the working of this particular program, It seems to be
I’m working on a problem which I know I can solve with C#. I
Ok, I'm trying to figure out which way would be faster to read a
Working in Linux and using C++. I have a program which initiates a thread.
I am working on a program which includes a general purpose engine, some program
I am working on a program written in Java which, for some actions ,
I'm new to Java, and I need some help working on this program. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.