Hello,
I have an ISAPI application that needs to write to the standard windows event log. The code works just fine when in a user mode process but, as soon as it runs from the ISAPI application, it generates an access denied error when calling RegisterEventSource (no matter what event source I pass it: "Application" fails as surely as anything else).
Server platform is IIS7 on windows 2003, language is Borland Delphi 6.
Edit: Code was requested so here it is:
procedure TExtendedEventLogger.LogMessage(Message: String; EventType: DWord;
Category: Word; ID: DWord);
var
P: Pointer;
USID: TUserSID;
begin
if Enabled then
begin
P := PChar(Message);
if FEventLog = 0 then
begin
If FMachine <> '' then
FEventLog := windows.RegisterEventSource(PChar(FMachine), PChar(FName))
else
FEventLog := windows.RegisterEventSource(nil, PChar(FName)); // <- blows up here
if FEventLog = 0 then
begin
Raise exception.Create('Event logging error: ' + SysErrorMessage(getLastError));
end;
end;
USID := GetCurrentUserSid();
try
if not ReportEvent(FEventLog, EventType, Category, ID, USID.PSID, 1, 0, @P, nil) then
raiseLastOSError;
finally
FreeAndNil(USID);
end;
end;
end;