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.DONT_RESOLVE_DLL_REFERENCES)
    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
 finally:
  win32api.RegCloseKey(handle)
 return (data or u'')

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 . DONT_RESOLVE_DLL_REFERENCES ) 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 finally : win32api . RegCloseKey ( handle ) return ( data or u'' )
given a tuple from readeventlog .