enumerateTraceGuids 函数 (evntrace.h)

EnumerateTraceGuids 函数检索有关计算机上当前运行的事件跟踪提供程序的信息。

重要

此函数已被 EnumerateTraceGuidsEx 取代。

语法

ULONG WMIAPI EnumerateTraceGuids(
  [in, out] PTRACE_GUID_PROPERTIES *GuidPropertiesArray,
  [in]      ULONG                  PropertyArrayCount,
  [out]     PULONG                 GuidCount
);

参数

[in, out] GuidPropertiesArray

指向 TRACE_GUID_PROPERTIES 结构的指针数组。 数组中的每个指针都必须指向具有空间的缓冲区,以存储 TRACE_GUID_PROPERTIES 结构。

[in] PropertyArrayCount

GuidPropertiesArray 数组中的指针数。

[out] GuidCount

接收计算机上注册的事件跟踪提供程序的实际数目。

返回值

如果函数成功,则返回值为 ERROR_SUCCESS。

如果函数失败,则返回值为 系统错误代码之一。 下面是一些常见错误及其原因。

  • ERROR_INVALID_PARAMETER

    下列情况之一存在:

    • PropertyArrayCount 为零
    • GuidPropertiesArrayNULL
  • ERROR_MORE_DATA

    属性数组太小,无法接收所有已注册提供程序的信息, (GuidCount 大于 PropertyArrayCount) 。 函数使用 PropertyArrayCount 中指定的结构数填充 GuidPropertiesArray

备注

此函数返回有关已通过 RegisterTraceGuidsEventRegister) (启动且尚未停止的事件跟踪提供程序的信息。

注意

若要获取有关已在系统 (注册的提供程序清单的信息,即通过 wevtutil) 注册的清单,请使用 TdhEnumerateProviders

可以使用 TRACE_GUID_PROPERTIES。LoggerId 成员,用于确定哪个会话最近启用了 提供程序(如果TRACE_GUID_PROPERTIES)。IsEnableTRUE

该列表将不包括 SystemTraceProvider 提供程序。

示例

以下示例演示如何调用此函数。

#include <windows.h>
#include <evntrace.h>
#include <vector>
#include <stdio.h>

int
wmain()
{
    ULONG status = 0;

    try
    {
        ULONG guidCount;
        std::vector<TRACE_GUID_PROPERTIES> guidPropValues;
        std::vector<TRACE_GUID_PROPERTIES*> guidPropPointers;

        // First call is just to get the actual count, so allocate a small buffer.
        guidCount = 1;

        // May need to retry multiple times since new providers could be added
        // between calls.
        for (;;)
        {
            ULONG const allocated = guidCount;
            guidPropValues.resize(allocated);
            guidPropPointers.resize(allocated);

            // Initialize the pointers to point at the values.
            for (ULONG i = 0; i != allocated; i += 1)
            {
                guidPropPointers[i] = &guidPropValues[i];
            }

            guidCount = 0;
            status = EnumerateTraceGuids(guidPropPointers.data(), allocated, &guidCount);
            if (status != ERROR_MORE_DATA)
            {
                guidPropValues.resize(guidCount);
                break;
            }

        }

        if (status != ERROR_SUCCESS)
        {
            printf("EnumerateTraceGuids error: %u\n", status);
        }
        else
        {
            printf("GuidCount = %lu\n", guidCount);
            for (auto const& v : guidPropValues)
            {
                printf("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x - %hs\n",
                    v.Guid.Data1, v.Guid.Data2, v.Guid.Data3,
                    v.Guid.Data4[0], v.Guid.Data4[1],
                    v.Guid.Data4[2], v.Guid.Data4[3], v.Guid.Data4[4],
                    v.Guid.Data4[5], v.Guid.Data4[6], v.Guid.Data4[7],
                    v.IsEnable ? "Enabled" : "Disabled");
            }
        }
    }
    catch (std::bad_alloc const&)
    {
        printf("Out of memory!\n");
        status = ERROR_OUTOFMEMORY;
    }

    return status;
}

要求

   
最低受支持的客户端 Windows XP [仅限桌面应用]
最低受支持的服务器 Windows Server 2003 [仅限桌面应用]
目标平台 Windows
标头 evntrace.h
Library Advapi32.lib
DLL Advapi32.dll

请参阅

EnumerateTraceGuidsEx

QueryAllTraces

TRACE_GUID_PROPERTIES