实现在应用层下遍历输出驱动文件路径列表信息。
实现代码:
#include <stdio.h> #include <windows.h> #include <Psapi.h> #include <shlwapi.h> #pragma comment(lib, "psapi.lib") #pragma comment(lib, "shlwapi.lib") #define ARRAY_SIZE 1024
int _tmain(int argc, _TCHAR* argv[]){ DWORD cbNeeded = 0; LPVOID drivers[ARRAY_SIZE] = {0}; int cDrivers = 0; if (EnumDeviceDrivers(drivers, sizeof(drivers), &cbNeeded) && cbNeeded < sizeof(drivers)) { char szDriver[ARRAY_SIZE] = {0}; char szPath[ARRAY_SIZE] = {0}; char szSystemPath[ARRAY_SIZE] = {0}; cDrivers = cbNeeded / sizeof(LPVOID); 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);
} } }
getchar(); return 0; }
|
代码基本上每一句都做了注释,应该蛮好理解的,效果图如下:
