我试图弄清楚如何使用 Windows 的事件跟踪......但我失败了。
为什么这段代码会给我错误代码ERROR_WMI_INSTANCE_NOT_FOUND
?
#include <stdio.h>
#include <tchar.h>
#include <Windows.h>
#include <Wmistr.h>
#include <Evntrace.h>
#include <evntcons.h>
ULONG NTAPI EtpEtwBufferCallback(IN PEVENT_TRACE_LOGFILE Buffer) { return TRUE; }
VOID NTAPI EtpEtwEventCallback(IN PEVENT_TRACE EventTrace) { }
int _tmain()
{
LPCTSTR loggerName = KERNEL_LOGGER_NAME;
EVENT_TRACE_LOGFILE logFile = {0};
logFile.LoggerName = const_cast<LPTSTR>(loggerName);
logFile.ProcessTraceMode = PROCESS_TRACE_MODE_REAL_TIME;
logFile.BufferCallback = EtpEtwBufferCallback;
logFile.EventCallback = EtpEtwEventCallback;
TRACEHANDLE hTrace = OpenTrace(&logFile);
ULONG result = ProcessTrace(&hTrace, 1, NULL, NULL);
// result is ERROR_WMI_INSTANCE_NOT_FOUND
_tprintf(_T("%u\n"), result);
}