Einzelnen Beitrag anzeigen

Astat

Registriert seit: 2. Dez 2009
Ort: München
320 Beiträge
 
Lazarus
 
#2

Re: Eventlog - Eigene Rubrik anlegen?

  Alt 19. Feb 2010, 16:24
Hallo, moelski.

1. Registry Eintrag setzen
2. Wenn notwendig Resourcen Dll erstellen
3. Dann als Sample mit SetEventLogStartUpInfos in die Section schreiben

Done!

Delphi-Quellcode:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\My Application Name]
"EventMessageFile"="%SystemRoot%\\system32\\eventres.dll"
"TypesSupported"=dword:00000007
"CategoryMessageFile"="%SystemRoot%\\system32\\eventres.dll"
"CategoryCount"=dword:00000002


library eventres;

  {$R ..\ResDLL\tada.res}


  {$R *.RES}
  
begin
end.


function WriteEventlog(szMsgArray: array of PChar; lpUNCServerName,
  szSourceName: PChar; EventType, CategoryID, EventID: Word;
  ptrBinaryData: Pointer; cbBinaryData: integer): boolean;
var
  hEventlog: THandle;
begin

  hEventLog := RegisterEventSource(lpUNCServerName, szSourceName);

  if hEventLog > 0 then begin

    ReportEvent(
      hEventLog,
      EventType,
      CategoryID,
      EventID,
      nil,
      Length(szMsgArray),
      cbBinaryData,
      @szMsgArray,
      ptrBinaryData
    );

    DeRegisterEventSource(hEventLog);
  end;
end;


procedure SetEventLogStartUpInfos;
var
  szMsgArray: array of PChar;
  ms: TMemoryStream;
begin
  SetLength(szMsgArray, 1);

  szMsgArray[0] := PChar(ParamStr(0)); //-- EventID = ResourceStringID %1
  //szMsgArray[1] := '10.4.126.34'; //-- EventID = ResourceStringID %2

  ms := TMemoryStream.Create;
  try
    ms.Write(_RegStruct, SizeOf(_RegStruct));

    WriteEventlog(
      szMsgArray, //-- szMsgArray: array of PChar;
      nil, //-- lpUNCServerName
      PChar('My Application Name'),//-- szSourceName
      EVENTLOG_INFORMATION_TYPE, //-- EventType
      1, //-- CategoryID
      3, //-- EventID (Resource String ID mit 2 Platzhalter)
      ms.Memory, //-- ptrBinaryData
      ms.Size //-- cbBinaryData
      );
  finally
    ms.free;
  end;
end;

lg. Astat
Lanthan Astat
06810110811210410503210511511603209711003210010110 9032084097103
03211611111604403209711003210010110903210010510103 2108101116122
11610103209010110510810103206711110010103210511003 2068101108112
10410503210310111509910411410510109810111003211910 5114100046
  Mit Zitat antworten Zitat