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的一篇博客,連接已找不到,遇到會補上。