C/C++ 应用层下遍历驱动列表
2023-02-18 16:46:18 时间
实现在应用层下遍历输出驱动文件路径列表信息。
实现代码:
#include <stdio.h>
#include <windows.h>
#include <Psapi.h>
#include <shlwapi.h> //PathFileExists
#pragma comment(lib, "psapi.lib")
#pragma comment(lib, "shlwapi.lib")
#define ARRAY_SIZE 1024
int _tmain(int argc, _TCHAR* argv[]){
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);
}
}
}
getchar();
return 0;
}
代码基本上每一句都做了注释,应该蛮好理解的,效果图如下:
相关文章
- Linux系列(20) - shutdown
- Linux系列(19) - 常用压缩命令(2)
- Linux系列(18) - 常用压缩命令(1)
- Linux系列(17) - >、>>的用法
- Linux系列(16) - 其他帮助命令
- Linux系列(15) - man
- Linux系列(14) - grep
- Linux系列(13) - CentOs 8 配置静态IP
- Linux系列(12) - find
- Linux系列(11) - PATH环境变量
- Linux系列(10) - 命令搜索命令whereis与which
- Linux系列(9) - whoami和whatis
- Linux系类(8) - 文件搜索命令locate
- Linux系列(7) - 链接命令
- Linux系列(6) - 常见目录
- Linux系列(5) - 目录处理命令(2)
- Linux系列(4) - 目录处理命令(1)
- Linux系列(3) - ls
- Linux系列(2) - 命令提示符
- Linux系列(1) - 使用Hyper-V安装Linux系统