Вот центральная часть моего C
кода, который используется с 2001 года:
// Open the Systemevent log.
h = OpenEventLog(name, // NULL = use local computer
"System"); // source name
if (h == NULL)
fatal("Could not open the System event log");
pevlr = (EVENTLOGRECORD *) &bBuffer;
time(&startTime);
startTime -= 30*24*3600L; // 30 days (~ 4 weeks) before now
start = 0;
prevDay = 0;
earliestTime = 0;
duration = 0;
// Opening the event log positions the file pointer for this
// handle at the beginning of the log. Read the records
// sequentially until there are no more.
while (ReadEventLog(h, // event log handle
EVENTLOG_FORWARDS_READ | // reads forward
EVENTLOG_SEQUENTIAL_READ, // sequential read
0, // ignored for sequential reads
pevlr, // pointer to buffer
BUFFER_SIZE, // size of buffer
&dwRead, // number of bytes read
&dwNeeded)) // bytes in next record
{
while (dwRead > 0)
{
// The source name is just past the end of the
// formal structure.
sourceName = (LPSTR) ((LPBYTE) pevlr + sizeof(EVENTLOGRECORD));
id = pevlr->EventID & 0x01FFF;
now = (time_t)(pevlr->TimeGenerated);
if (((id == EL_START) || (id == EL_END)) &&
(now >= startTime) &&
!strcmp(sourceName, "EventLog"))
{
if (!earliestTime)
earliestTime = now;
dwThisRecord++;
tm = localtime(&now);
day = tm->tm_mday;
if (day != prevDay)
{
printf("\n%s ", DateStamp(&now));
if (id == EL_END)
printf(" ... ");
}
else if (id == EL_START)
printf("\n ");
if (id == EL_START)
{
if (start)
{
printf("%s ... (no end time!)", TimeStamp(&start));
printf("\n %s", TimeStamp(&now));
}
else
{
printf("%s ... ", TimeStamp(&now));
}
start = now;
}
else
{
if (start)
{
printf("%s ", TimeStamp(&now));
printf("%s", Duration(now - start));
duration += (now - start);
}
else
{
printf(" ... %s (no start time!)", TimeStamp(&now));
}
start = 0;
}
prevDay = day;
}
dwRead -= pevlr->Length;
pevlr = (EVENTLOGRECORD *) ((LPBYTE) pevlr + pevlr->Length);
}
pevlr = (EVENTLOGRECORD *) &bBuffer;
}
CloseEventLog(h);