GetNumberOfEventLogRecords返回错误的事件日志数
GetNumberOfEventLogRecords returns incorrect number of event logs
我有这个c++代码来读取事件日志记录
DWORD GetLogRecords(LPCWSTR wsLogFile)
{
HANDLE hEvt = OpenEventLog(NULL, wsLogFile);
if (hEvt==NULL) return 0;
DWORD dwTotalRecords;
BOOL res = GetNumberOfEventLogRecords(hEvt, &dwTotalRecords);
CloseEventLog(hEvt);
return (res != 0) ? dwTotalRecords : 0;
}
结果atlTraceGeneral - C:Windowssystem32winevtlogsACEEventLog.evtx - 23499 Total Records
atlTraceGeneral - C:Windowssystem32winevtlogsApplication.evtx - 23499 Total Records
atlTraceGeneral - C:Windowssystem32winevtlogsConnectionInfo.evtx - 23499 Total Records
atlTraceGeneral - C:Windowssystem32winevtlogsError.evtx - 23499 Total Records
atlTraceGeneral - C:Windowssystem32winevtlogsHardwareEvents.evtx - 23499 Total Records
atlTraceGeneral - C:Windowssystem32winevtlogsInternet Explorer.evtx - 23499 Total Records
atlTraceGeneral - C:Windowssystem32winevtlogsKey Management Service.evtx - 23499 Total Records
...
我用我计算机上所有. evtx日志文件(150个日志文件)的完整路径调用了这个函数。每次它都返回23499 !我的日志文件大小不一,有些是0,为什么我总是得到23499 ?
UPDATE2:在我清除了应用程序日志之后,现在我得到所有.evtx日志文件的0。我认为它总是得到应用程序日志,而不是指定的。evtx文件。
更新:正如Remy Lebeau建议的那样,但结果仍然相同。
为了其他人的利益,这个问题的解决方案是OpenEventLog
不接受路径名。相反,您必须为它指定事件日志的源名称(例如"HardwareEvents"
)。
如果您使用无效的源名称调用OpenEventLog
(其中包括提供路径名),那么根据文档,它将打开Application
日志:
如果您指定的自定义日志无法找到,则事件日志service打开应用程序日志
您没有检查GetNumberOfEventLogRecords()
的结果是否有错误。你的木头把手漏了。试试这个:
DWORD GetLogRecords(LPCWSTR wsLogFile)
{
HANDLE hEvt = OpenEventLog(NULL, wsLogFile);
if (hEvt==NULL) return 0;
DWORD dwTotalRecords;
BOOL res = GetNumberOfEventLogRecords(hEvt, &dwTotalRecords);
CloseEventLog(hEvt);
return (res != 0) ? dwTotalRecords : 0;
}
相关文章:
- Android NDK传感器向事件队列报告奇怪的间隔
- 从文本文件中读取时钟时间和事件时间并进行处理
- WMI检测进程创建事件-c++
- EvtExportLogneneneba API正在将远程计算机的事件日志保存到远程PC本身.如何将其保存到主机
- 处理闪烁窗口事件
- C++Builder中的OnClick事件签名存在问题
- 返回ERROR_INVALID_PARAMETER的事件日志函数
- 尝试使用 EvtSetChannelConfigProperty() 函数更新最大事件日志文件大小时插入的错误值
- 查询事件日志.如何查询才能单独获取第一个和最后一个事件?
- 如何使用 c++ 在 "Application and Services Logs" 部分创建事件日志
- "正在初始化":无法从"事件日志记录 *"转换为"事件日志记录 []"
- 如何将Windows事件日志刷新到磁盘
- 事件记录API未写入系统日志
- 如何从Windows XP下的程序中知道或更改Windows事件日志的大小
- Windows 事件日志中没有类别
- 如何在Windows XP中检索所有事件日志
- 如何在VC++中不使用.NET Framework来确定特定事件日志是否存在
- 无Admin权限使用Windows api收集事件日志
- GetNumberOfEventLogRecords返回错误的事件日志数
- 如何获取所有可用的事件日志名称