#include #include int GetEventRecordCount(const wchar_t* logName) { HANDLE hEventLog = NULL; DWORD recordCount; DWORD bytesRead; BYTE buffer[4096]; BOOL success; // イベントログを開く hEventLog = OpenEventLog(NULL, logName); if (hEventLog == NULL) { printf("イベントログのオープンに失敗しました: %lu\n", GetLastError()); return -1; } // イベントログを読み取りながらレコード数をカウント recordCount = 0; success = ReadEventLog(hEventLog, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ, 0, buffer, sizeof(buffer), &bytesRead, &recordCount); while (success && bytesRead > 0) { EVENTLOGRECORD* pLogRecord = (EVENTLOGRECORD*)buffer; while ((BYTE*)pLogRecord < buffer + bytesRead) { // レコードを処理 recordCount++; // 次のレコードに移動 pLogRecord = (EVENTLOGRECORD*)((BYTE*)pLogRecord + pLogRecord->Length); } success = ReadEventLog(hEventLog, EVENTLOG_SEQUENTIAL_READ | EVENTLOG_FORWARDS_READ, 0, buffer, sizeof(buffer), &bytesRead, &recordCount); } // ハンドルをクローズ CloseEventLog(hEventLog); return recordCount; } int main() { const wchar_t* logName = L"Application"; // チェックするイベントログの名前 int recordCount = GetEventRecordCount(logName); if (recordCount >= 0) { printf("イベントログのレコード数: %d\n", recordCount); } else { printf("イベントログのレコード数の取得に失敗しました\n"); } return 0; }