博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Windows Event Log相关函数使用(1)
阅读量:6590 次
发布时间:2019-06-24

本文共 3162 字,大约阅读时间需要 10 分钟。

 

一.EvtOpenLog

The EvtOpenLog function opens an exported or live event log and returns a handle that can be used to access the log. The returned handle can be used by subsequent calls to the EvtGetLogInfo function.

示例:

EVT_HANDLE log = NULL;      LPCWSTR logPath = L"SimpleOperationalChannel";log = EvtOpenLog( NULL, logPath, EvtOpenChannelPath);if(log == NULL){    wprintf(L"Error opening the log: 0x%x \n", GetLastError());    return 1;}

二.EvtClose

The EvtClose function closes an open event object handle that was previously returned from a Windows Event Log function. Any handle that is returned by a Windows Event Log function must be closed using this function call when the user is finished with the handle. The handle that is passed into this function becomes invalid after this function is successfully called.

EVT_HANDLE log = NULL;      LPCWSTR logPath = L"SimpleOperationalChannel";log = EvtOpenLog( NULL, logPath, EvtOpenChannelPath);...EvtClose(log);

三.EvtGetLogInfo

The EvtGetEventInfo function allows the caller to determine which clause in an event query or subscription filter selected a given event or to determine the channel or log that the event came from.

可查询的字段

typedef enum _EVT_LOG_PROPERTY_ID{    EvtLogCreationTime = 0,             // EvtVarTypeFileTime    EvtLogLastAccessTime,               // EvtVarTypeFileTime    EvtLogLastWriteTime,                // EvtVarTypeFileTime    EvtLogFileSize,                     // EvtVarTypeUInt64    EvtLogAttributes,                   // EvtVarTypeUInt32    EvtLogNumberOfLogRecords,           // EvtVarTypeUInt64    EvtLogOldestRecordNumber,           // EvtVarTypeUInt64    EvtLogFull,                         // EvtVarTypeBoolean} EVT_LOG_PROPERTY_ID;

示例:

EVT_VARIANT* logProperty = (EVT_VARIANT*) malloc (sizeof (EVT_VARIANT));DWORD bufferSize = sizeof(EVT_VARIANT);if( !EvtGetLogInfo(log, EvtLogNumberOfLogRecords, bufferSize, logProperty, &bufferSize)){       //...}if(logProperty->Type == EvtVarTypeNull){    wprintf(L"The value of the log number of events property is NULL.\n");}else{    wprintf(L"The value of the log number of events property is: %I64u \n",         logProperty->UInt64Val);}

四.日志操作维护

1.EvtClearLog

The EvtClearLog function clears all events from an active log and exports the events to a target log file.

示例:

if ( !EvtClearLog(NULL,     L"Application",    L"c:\\temp\\MyClearedEvents.log",     0 ))    return GetLastError();

注意点:目录必须存在

2.EvtExportLog

The EvtExportLog function exports selected events from a channel or from a log file to a target log file based on an event query.

if ( !EvtExportLog(NULL,     L"Application",    L"*",    L"c:\\MyExportedEvents.log",     EvtExportLogChannelPath ))    return GetLastError();

3.EvtArchiveExportedLog

The EvtArchiveExportedLog function archives localized information associated with the events in specified logs that have been created by either the EvtClearLog function or the EvtExportLog function.

示例:

if ( !EvtArchiveExportedLog(NULL,     L"c:\\MyExportedEvents.log",     MAKELCID( MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT ),    0 ))    return GetLastError();

存档的日志在此目录下:C:\Windows\System32\winevt\Logs

转载地址:http://pozio.baihongyu.com/

你可能感兴趣的文章
nginx+ffmpeg搭建rtmp转播rtsp流的flash服务器
查看>>
Win10 IoT C#开发 1 - Raspberry安装IoT系统及搭建开发环境
查看>>
关于在arm裸板编程时使用printf问题的解决方法
查看>>
开源人工智能技术将改变一切
查看>>
2015 上半年 JavaScript 使用统计数据
查看>>
《Python算法教程》——1.6 如果您感兴趣
查看>>
干货 | 豆子科技首席架构师钟声:Java的纯真年代
查看>>
深度解析Java8 – AbstractQueuedSynchronizer的实现分析(下)
查看>>
SSH原理与运用(一):远程登录
查看>>
Spring Framework 4.2 中的新功能和增强功能
查看>>
动态代理解决网站字符集编码
查看>>
我所想的GIX4的权限
查看>>
Hbuilder--让手爽,飞一般的编码(二)
查看>>
后台统计
查看>>
React组件: 提取图片颜色
查看>>
3D应用开发中的欧拉角和旋转矩阵
查看>>
爬虫必备技能xpath的用法和实战
查看>>
MacOS下安装Grafana、InfluxData、telegraf
查看>>
RxJava2.0的初学者必备教程(九)
查看>>
记一次omi的项目之旅
查看>>