Domanda

Per quanto ho capito, il ReportEvent la funzione richiede File di testo del messaggio Associato attraverso il registro per ricevere messaggi correttamente formattati. Esistono ID eventi comuni o un modo semplice per segnalare un evento senza file di testo dei messaggi associati?

Oppure può essere, esiste una fonte di evento comune speciale che posso usare nella mia applicazione? Qualcosa come RegisterEventSource (null, "applicazione")?

È stato utile?

Soluzione

No, devi solo seguire le regole e definire i file di testo del messaggio, costruirli in risorse, collegarli alla tua app ecc.

Il Esempio fornito su MSDN Ti conduce attraverso tutto ciò che devi fare.

Altri suggerimenti

Provalo, ha funzionato per me prima ..

http://www.codeproject.com/kb/system/xeventlog.aspx

Non lo fai avere Per registrare i tuoi messaggi in HKLM. (Che è una buona cosa, perché tu Non posso Registra i messaggi se non sei un amministratore).

Ma ciò non ti impedisce di scrivere eventi al registro eventi dell'applicazione di Windows. L'unico aspetto negativo è che a partire da Windows Vista otterrai solo un brutto testo insieme ad esso.

HRESULT LogToEventLog(String Source, String EventText, int EventType, DWORD EventID)
{
   /*
      EventType is one of:
         EVENTLOG_ERROR_TYPE       = $0001;
         EVENTLOG_WARNING_TYPE     = $0002;
         EVENTLOG_INFORMATION_TYPE = $0004;
         EVENTLOG_AUDIT_SUCCESS    = $0008;
         EVENTLOG_AUDIT_FAILURE    = $0010;

      Source is your name for your app or feature, e.g.:
         "My Cool App"
         "Outlook"    
         "ESENT"
         "Chrome"
   */

   HANDLE h = RegisterEventSource(null, Source); //null --> local computer
   if (h == 0) 
      return HResultFromWin32(GetLastError);
   try
   {       
      PChar[1] ss;
      ss[0] = PChar(EventText);

      if (!ReportEvent(
            h,         // event log handle
            EventType, // event type
            0,         // category zero
            EventID,   // event identifier
            null,      // no user security identifier
            1,         // one substitution string
            0,         // no data
            @ss,       // pointer to string array
            null       // pointer to data
      ))
      {
         return HResultFromWin32(GetLastError);
      }
   }
   finally
   {
      DeregisterEventSource(h);
   }
   return S_OK;
}

E quindi ora puoi registrare eventi al registro degli eventi dell'applicazione:

LogToEventLog("Stackoverflow", "Question 5399066 was answered by Ian Boyd", 
      EVENTLOG_INFORMATION_TYPE, 0x45);

Rubare la registrazione di qualcun altro

Sfortunatamente, a partire da Windows Vista, Windows fornirà brutte lamentele che non hai registrato in anticipo l'evento:

Non è possibile trovare la descrizione per l'ID evento 69 da fonte StackOverflow. O il componente che solleva questo evento non è installato sul computer locale o l'installazione è danneggiato. È possibile installare o riparare il componente sul computer locale.

Se l'evento è nato su un altro computer, le informazioni sul display dovevano essere salvate con l'evento.

Le seguenti informazioni sono state incluse nell'evento:

La domanda 5399066 è stata data risposta da Ian Boyd

Ma non lo fai avere per conviverci. Solo perché non hai registrato un file di origine del messaggio in HKLM, non significa che nessun altro lo abbia fatto.

Si noti, ad esempio, un messaggio da Veduta Fonte nel registro degli eventi:

  • Fonte: Outlook
  • Eventid: 0x40000020
  • Dati degli eventi: D:\win32app\Exchange\Outlook2003.pst
  • Messaggio: The store D:\win32app\Exchange\Outlook2003.pst has detected a catalog checkpoint.

Puoi controllare le informazioni di registrazione per Veduta in:

HKEY_LOCAL_MACHINE SYSTEM CurrentControlset Services eventlog Application Outlook

E vedi:

MessageEventFile: REG_SZ = "D:\Programs\MICROS~4\Office14\1033\MAPIR.DLL"

Se sbirciate nelle risorse del binario mapir.dll, vedrai il suo Tabella dei messaggi:

1 MESSAGETABLE
{
0x12,       "Connection stats for server (%1).  Rpcs Attempted (%2), Rpcs Succeeded (%3), Rpcs Failed (%4), Rpcs Canceled (%5), Rpc UI shown (%6), Avg request time (%7) ms, Min request time (%8) ms, Max request time (%9) ms.\r\n"
0x14,       "Cancelable RPC started.\r\n"
0x15,       "Cancelable RPC shutdown.\r\n"
0x40000010,     "Cancelable RPC dialog shown for server (%1), total wait time was (%2) ms, result was (%3).\r\n"
0x40000011,     "User canceled request against server (%1) after waiting (%2) ms.\r\n"
0x40000013,     "Rpc call (%1) on transport (%2) to server (%3) failed with error code (%4) after waiting (%5) ms; eeInfo (%6).\r\n"
0x40000016,     "There was a problem reading one or more of your reminders. Some reminders may not appear.\r\n"
0x40000017,     "Unable to update public free/busy data.\r\n"
0x4000001A,     "%1\r\n"
0x4000001B,     "%1\r\n"
0x4000001D,     "The store %1 is being re-pushed to the indexer for the following reason: %2.\r\n"
0x4000001E,     "Starting reconciliation for the store %1 for the following reason: %2.\r\n"
0x4000001F,     "The store %1 has detected a catalog rebuild.\r\n"
0x40000020,     "The store %1 has detected a catalog checkpoint.\r\n"
...
}

Puoi vedere che EventID 0x40000020 è associato a una stringa di formattazione:

"Il negozio %1 ha rilevato un checkpoint del catalogo. R n"

Puoi dirottare la registrazione di Outlook:

LogToEventLog("Outlook", "Your mom", EVENTLOG_INFORMATION_TYPE, $40000020);

E riceverai il tuo evento aggiunto al registro degli eventi senza tutti gli avvertimenti brutti:

enter image description here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top