列出Windows全部设备驱动名

Windows驱动名打印

#include <stdio.h>
#include <Psapi.h>
#include <Shlwapi.h>
#include <Windows.h>

#pragma comment(lib, "psapi.lib")
#pragma comment(lib, "shlwapi.lib")

#define  ARRAY_SIZE 1024


int main()
{
    DWORD cbNeeded = 0; // drivers[] 返回的字节数
    LPVOID drivers[ARRAY_SIZE] = { 0 }; // 驱动程序地址列表数组
    int cDrivers = 0;	// 驱动个数
    if (EnumDeviceDrivers(drivers, sizeof(drivers), &cbNeeded) && cbNeeded < sizeof(drivers)) // EnumDeviceDrivers 检索每一个驱动文件的加载地址
    {
        char szDriver[ARRAY_SIZE] = { 0 };	// 驱动文件名
        char szPath[ARRAY_SIZE] = { 0 };	// 存放驱动文件全路径
        char szSystemPath[ARRAY_SIZE] = { 0 }; // 存放 system32 文件夹路径
        cDrivers = cbNeeded / sizeof(LPVOID);	// 驱动个数

        // 获得C:\Windows\system32\dbghelp.dll
        GetSystemDirectory(szSystemPath, sizeof(szSystemPath));
        strcat_s(szSystemPath, "\\dbghelp.dll");

        for (int i = 0; i < cDrivers; i++)
        {
            if (GetDeviceDriverBaseName(drivers[i], szDriver, sizeof(szDriver) / sizeof(LPVOID)))
            {
            // 打印驱动名
            printf("【%d】:%s\n", i + 1, szDriver);

            // 打印驱动文件路径
            // GetDeviceDriverFileName(drivers[i], szPath, sizeof(szPath));
            // printf("%s\n", szPath);
            }
        }
    }
}
内容来自CSDN的一篇博客,连接已找不到,遇到会补上。
相关文章
相关标签/搜索