Example #1
0
def ReportEvent(
    appName,
    eventID,
    eventCategory=0,
    eventType=win32evtlog.EVENTLOG_ERROR_TYPE,
    strings=None,
    data=None,
    sid=None,
):
    """Report an event for a previously added event source."""
    # Get a handle to the Application event log
    hAppLog = win32evtlog.RegisterEventSource(None, appName)

    # Now report the event, which will add this event to the event log */
    win32evtlog.ReportEvent(
        hAppLog,  # event-log handle \
        eventType,
        eventCategory,
        eventID,
        sid,
        strings,
        data,
    )

    win32evtlog.DeregisterEventSource(hAppLog)
Example #2
0
    def __enter__(self):
        # This requires that tests are executed in an administrator shell, useful for testing handling of Error 15027
        # win32evtlogutil.AddSourceToRegistry(self.source)

        # https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-registereventsourcea
        # http://timgolden.me.uk/pywin32-docs/win32evtlog__RegisterEventSource_meth.html
        self.log_handle = win32evtlog.RegisterEventSource(None, self.source)
        return self