home *** CD-ROM | disk | FTP | other *** search
Wrap
# Source Generated with Decompyle++ # File: in.pyo (Python 2.7) import win32api import win32con import winerror import win32evtlog error = win32api.error langid = win32api.MAKELANGID(win32con.LANG_NEUTRAL, win32con.SUBLANG_NEUTRAL) def AddSourceToRegistry(appName, msgDLL = None, eventLogType = 'Application', eventLogFlags = None): if msgDLL is None: msgDLL = win32evtlog.__file__ hkey = win32api.RegCreateKey(win32con.HKEY_LOCAL_MACHINE, 'SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s' % (eventLogType, appName)) win32api.RegSetValueEx(hkey, 'EventMessageFile', 0, win32con.REG_EXPAND_SZ, msgDLL) if eventLogFlags is None: eventLogFlags = win32evtlog.EVENTLOG_ERROR_TYPE | win32evtlog.EVENTLOG_WARNING_TYPE | win32evtlog.EVENTLOG_INFORMATION_TYPE win32api.RegSetValueEx(hkey, 'TypesSupported', 0, win32con.REG_DWORD, eventLogFlags) win32api.RegCloseKey(hkey) def RemoveSourceFromRegistry(appName, eventLogType = 'Application'): try: win32api.RegDeleteKey(win32con.HKEY_LOCAL_MACHINE, 'SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s' % (eventLogType, appName)) except win32api.error: exc = None if exc.winerror != winerror.ERROR_FILE_NOT_FOUND: raise def ReportEvent(appName, eventID, eventCategory = 0, eventType = win32evtlog.EVENTLOG_ERROR_TYPE, strings = None, data = None, sid = None): hAppLog = win32evtlog.RegisterEventSource(None, appName) win32evtlog.ReportEvent(hAppLog, eventType, eventCategory, eventID, sid, strings, data) win32evtlog.DeregisterEventSource(hAppLog) def FormatMessage(eventLogRecord, logType = 'Application'): keyName = 'SYSTEM\\CurrentControlSet\\Services\\EventLog\\%s\\%s' % (logType, eventLogRecord.SourceName) handle = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, keyName) try: dllNames = win32api.RegQueryValueEx(handle, 'EventMessageFile')[0].split(';') data = None for dllName in dllNames: try: dllName = win32api.ExpandEnvironmentStrings(dllName) dllHandle = win32api.LoadLibraryEx(dllName, 0, win32con.LOAD_LIBRARY_AS_DATAFILE) try: data = win32api.FormatMessageW(win32con.FORMAT_MESSAGE_FROM_HMODULE, dllHandle, eventLogRecord.EventID, langid, eventLogRecord.StringInserts) finally: win32api.FreeLibrary(dllHandle) except win32api.error: pass if data is not None: break continue finally: win32api.RegCloseKey(handle) if not data: pass return u'' def SafeFormatMessage(eventLogRecord, logType = None): if logType is None: logType = 'Application' try: return FormatMessage(eventLogRecord, logType) except win32api.error: if eventLogRecord.StringInserts is None: desc = '' else: desc = u', '.join(eventLogRecord.StringInserts) return u'<The description for Event ID ( %d ) in Source ( %r ) could not be found. It contains the following insertion string(s):%r.>' % (winerror.HRESULT_CODE(eventLogRecord.EventID), eventLogRecord.SourceName, desc) def FeedEventLogRecords(feeder, machineName = None, logName = 'Application', readFlags = None): if readFlags is None: readFlags = win32evtlog.EVENTLOG_BACKWARDS_READ | win32evtlog.EVENTLOG_SEQUENTIAL_READ h = win32evtlog.OpenEventLog(machineName, logName) try: while None: objects = win32evtlog.ReadEventLog(h, readFlags, 0) if not objects: break win32evtlog.CloseEventLog(h) return None