Autor |
Beitrag |
Gast
Gast
Erhaltene Danke: 1
|
Verfasst: Mo 07.07.03 23:26
Hallo,
hab ein kleines schmutziges Prograemmchen zusammengehackt. Es alarmiert einen, sobald ein neues Ereignis in der Eventlog auftaucht.
Es blinkt dann ein TrayIcon! Ansonsten zeigt der TrayIcon-Hint an, wieviele Ereignisse in den einzelnen Logs sind.
Doppelklick aufs Icon oeffnet den EventViewer ... Rechtsklick beendet EventMonTray ... sicher noch erweiterungs- und verbesserungsbeduerftig ... aber es ist eben nur ein 2 Stunden-Proggy
Viel Spass damit ... ist allerdings nur der "Quick'n'Dirty approach"
Die wichtigen Parts sind:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
| function MonitorThread(lParam: PNotifyIconData): DWORD; stdcall; var i: Integer; ret: DWORD; begin ResetCounter; for i := 0 to idx - 1 do NotifyChangeEventLog(logs[i], events[i]); while True do begin ret := WaitForMultipleObjects(idx, @events, False, 1000); if ret <> WAIT_TIMEOUT then begin Blink := True; ModifyTrayIconText; end; end; result := 0; end; |
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20:
| err := RegOpenKey(HKEY_LOCAL_MACHINE, servicekey, hReg); if err = ERROR_SUCCESS then try bufsize := sizeof(namebuf); ZeroMemory(@namebuf, bufsize); idx := 0; while RegEnumKeyEx(hReg, idx, @namebuf, bufsize, nil, nil, nil, @ft) = ERROR_SUCCESS do begin events[idx] := CreateEvent(nil, True, False, @Format(EventPrefix, [@namebuf])[1]); logs[idx] := OpenEventLog(nil, @namebuf); SetString(lognames[idx], PChar(@namebuf), lstrlen(@namebuf)); bufsize := sizeof(namebuf); ZeroMemory(@namebuf, bufsize); inc(idx); if idx > maxlogs then Break; end; finally RegCloseKey(hReg); end; |
Downloadbar als RAR und ZIP
PS: In der DP auch gepostet.
|
|
mimi
Beiträge: 3458
Ubuntu, Win XP
Lazarus
|
Verfasst: Mi 09.07.03 21:45
nicht schlecht, wars nicht schlecht wäre wenn man die ereignise gleich im programm sehen könnte(z.b. so wie das der ereignis manger von windows tut)
_________________ MFG
Michael Springwald, "kann kein englisch...."
|
|
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1
|
Verfasst: Mi 09.07.03 22:22
Soll wohl nur ein HowTo sein, also das Prinzip zeigen und dazu dienen es selbst etwas auszubauen und für seine Bedürfnisse anzupassen.
|
|
Gast
Gast
Erhaltene Danke: 1
|
Verfasst: Mi 09.07.03 23:10
Titel: EvenlogLister ...
Ein simples Konsolenprogramm, das alle Events aus allen Logs listet, die es finden kann, wenn das Programm startet.
Es wird keine Konvertierung in menschenlesbare Werte gemacht. Dies obliegt jenen, die den Source weiterverwenden wollen.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222:
|
program eventlog; uses Windows;
{$INCLUDE .\Include\FormatString.pas} {$APPTYPE CONSOLE}
const servicekey = 'SYSTEM\CurrentControlSet\Services\Eventlog';
const EVENTLOG_SEQUENTIAL_READ = $0001; EVENTLOG_SEEK_READ = $0002; EVENTLOG_FORWARDS_READ = $0004; EVENTLOG_BACKWARDS_READ = $0008;
EVENTLOG_SUCCESS = $0000; EVENTLOG_ERROR_TYPE = $0001; EVENTLOG_WARNING_TYPE = $0002; EVENTLOG_INFORMATION_TYPE = $0004; EVENTLOG_AUDIT_SUCCESS = $0008; EVENTLOG_AUDIT_FAILURE = $0010;
EVENTLOG_START_PAIRED_EVENT = $0001; EVENTLOG_END_PAIRED_EVENT = $0002; EVENTLOG_END_ALL_PAIRED_EVENTS = $0004; EVENTLOG_PAIRED_EVENT_ACTIVE = $0008; EVENTLOG_PAIRED_EVENT_INACTIVE = $0010;
type PEVENTLOGRECORD = ^EVENTLOGRECORD; EVENTLOGRECORD = packed record Length, Reserved, RecordNumber, TimeGenerated, TimeWritten, EventID: DWORD; EventType, NumStrings, EventCategory, ReservedFlags: Word; ClosingRecordNumber, StringOffset, UserSidLength, UserSidOffset, DataLength, DataOffset: DWORD; end;
function UnixTimeToFileTime(t: LongWord): FILETIME; var ll: int64; begin ll := (Int64(t) * 10000000) + int64(116444736000000000); result.dwLowDateTime := LongWord(ll); result.dwHighDateTime := ll shr 32; end;
function GetDateString(ft: FILETIME): string; var st: SYSTEMTIME; begin FileTimeToSystemTime(ft, st); result := Format('%4.4d-%2.2d-%2.2d@%2.2d:%2.2d:%2.2d', [st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond]); end;
var idx: Integer; hReg: HKEY; needed, oldrec, numrecs, bufsize, err: DWORD; ft: FILETIME; namebuf: array[0..MAX_PATH] of char; log: THandle; elr: EVENTLOGRECORD; pelr: PEVENTLOGRECORD; begin err := RegOpenKey(HKEY_LOCAL_MACHINE, servicekey, hReg); if err = ERROR_SUCCESS then try bufsize := sizeof(namebuf); ZeroMemory(@namebuf, bufsize); idx := 0; while RegEnumKeyEx(hReg, idx, @namebuf, bufsize, nil, nil, nil, @ft) = ERROR_SUCCESS do try log := OpenEventLog(nil, @namebuf); if GetNumberOfEventLogRecords(log, numrecs) then if GetOldestEventLogRecord(log, oldrec) then for err := oldrec to oldrec + numrecs - 1 do if not ReadEventLog(log, EVENTLOG_SEEK_READ or EVENTLOG_FORWARDS_READ, err, @elr, 0, bufsize, needed) then if GetLastError = ERROR_INSUFFICIENT_BUFFER then begin GetMem(pelr, needed); if Assigned(pelr) then try if ReadEventLog(log, EVENTLOG_SEEK_READ or EVENTLOG_FORWARDS_READ, err, pelr, needed, bufsize, needed) then begin Writeln(Format('Record: %6.6d - EventID: %6.6d - EventType: %6.6d', [pelr^.RecordNumber, pelr^.EventID, pelr^.EventType])); Writeln(' Logged : ',GetDateString(UnixTimeToFileTime(pelr^.TimeGenerated)), ' Written: ',GetDateString(UnixTimeToFileTime(pelr^.TimeWritten))); end; finally FreeMem(pelr); end; end; bufsize := sizeof(namebuf); ZeroMemory(@namebuf, bufsize); inc(idx); finally CloseEventlog(log); end; finally RegCloseKey(hReg); end; end. |
Download als eventloglister.zip/rar/ace unter: assarbad.net/stuff/
Wenn die Mods wollen, können sie das gern verschieben zu den OpenSource-Proggies ;)
|
|
Gast
Gast
Erhaltene Danke: 1
|
Verfasst: Fr 11.07.03 00:46
Es gelten die Bedingungen der BSDL
Menschenlesbarkeit ist nun drin! Hier die wichtigsten Funktionen.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126:
| function GetEventIDText(EventID: DWORD; msgfile: string; pelr: PEVENTLOGRECORD): string; type PVA_LIST = ^VA_LIST; VA_LIST = array[0..0] of Pointer; var hLib: THandle; ret, flags, nSize: DWORD; ppc, pc, lpc: PChar; i: Integer; begin result := ''; flags := FORMAT_MESSAGE_FROM_HMODULE or FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_ARGUMENT_ARRAY or FORMAT_MESSAGE_IGNORE_INSERTS; nSize := ExpandEnvironmentStrings(@msgfile[1], nil, 0) + 2; GetMem(pc, nSize); if Assigned(pc) then try ZeroMemory(pc, nSize); ExpandEnvironmentStrings(@msgfile[1], pc, nSize); for i := lstrlen(pc) - 1 downto 0 do if pc[i] = ';' then pc[i] := #0; lpc := pc; while lpc[0] <> #0 do begin hLib := LoadLibraryEx(lpc, 0, DONT_RESOLVE_DLL_REFERENCES); inc(lpc, lstrlen(lpc) + 1); if hLib <> 0 then try ret := FormatMessage(flags, Pointer(hLib), EventID, LANG_USER_DEFAULT, @ppc, 0, nil); if ((ret = 0) and (GetLastError = ERROR_MR_MID_NOT_FOUND) and (lpc[0] <> #0)) then Continue; finally FreeLibrary(hLib); end; end; if ret <> 0 then SetString(result, ppc, lstrlen(ppc)); if Assigned(ppc) then LocalFree(THandle(ppc)); finally Freemem(pc); end; end;
function GetEventRecordString(pelr: PEVENTLOGRECORD; el: PChar): MYEVENTLOGRECORD;
const elkey = 'SYSTEM\CurrentControlSet\Services\Eventlog\'; var ft: FILETIME; pc: PChar; uName, dName: array[0..MAX_PATH - 1] of Char; err, uSize, dSize, use: DWORD; key: HKEY; temps: string; begin ZeroMemory(@result, sizeof(result)); result.RecordNumber := pelr^.RecordNumber; result.EventID := pelr^.EventID; ft := UnixTimeToFileTime(pelr^.TimeGenerated); FileTimeToLocalFileTime(ft, result.LocalTimeGenerated); ft := UnixTimeToFileTime(pelr^.TimeWritten); FileTimeToLocalFileTime(ft, result.LocalTimeWritten); result.EventType := pelr^.EventType; result.EventCategory := pelr^.EventCategory; if pelr^.DataLength <> 0 then begin SetLength(result.Data, pelr^.DataLength); CopyMemory(@result.Data[1], PAdd(pelr, pelr^.DataOffset), pelr^.DataLength); end; pc := PAdd(pelr, sizeof(pelr^)); SetString(result.SourceName, pc, lstrlen(pc)); inc(pc, lstrlen(pc) + 1); SetString(result.ComputerName, pc, lstrlen(pc)); uSize := sizeof(uName); dSize := sizeof(dName); if pelr^.UserSidLength <> 0 then if LookUpAccountSid(pc, PAdd(pelr, pelr^.UserSidOffset), uName, uSize, dName, dSize, use) then result.UserName := Format('\\%s\%s', [@dName, @uName]); temps := elkey + string(el) + '\' + result.SourceName; err := RegOpenKey(HKEY_LOCAL_MACHINE, @temps[1], key); if err = ERROR_SUCCESS then try dSize := 0; RegQueryValueEx(key, 'EventMessageFile', nil, nil, nil, @dSize); begin GetMem(pc, dSize); if Assigned(pc) then try ZeroMemory(pc, dSize); if RegQueryValueEx(key, 'EventMessageFile', nil, nil, PByte(pc), @dSize) = ERROR_SUCCESS then SetString(result.SourceFile, pc, lstrlen(pc)); finally FreeMem(pc); end; end; finally RegCloseKey(key); end; if result.SourceFile <> '' then result.MessageText := GetEventIDText(result.EventID, result.SourceFile, pelr); end; |
|
|
|