• C/C++ 遍历驱动列表(应用层下)


    实现代码:

    #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:Windowssystem32dbghelp.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
    ", i+1, szDriver);
    
    				// 打印驱动文件路径
    				//GetDeviceDriverFileName(drivers[i], szPath, sizeof(szPath));
    				//printf("%s
    ", szPath);
                }
            }
        }
    
    	getchar();
    	return 0;
    }
    

    代码基本上每一句都做了注释,应该蛮好理解的,效果图如下:

    最后感谢JoyChou老哥提供的思路:https://www.52pojie.cn/thread-243050-1-1.html


    版权声明: 本博客,文章与代码均为学习时整理的笔记,博客中除去明确标注有参考文献的文章,其他文章【均为原创】作品,转载请务必【添加出处】,您添加出处是我创作的动力!

    警告:如果您恶意转载本人文章,则您的整站文章,将会变为我的原创作品,请相互尊重!
  • 相关阅读:
    请求重定向,请求转发
    post、get方法乱码问题
    Servlet
    修改Servlet模板,让Servlet更清新
    Java-Python对垒之质数计算
    使用Packet Tracer对不同网段组网模拟
    哑编码的两种方法
    AdaBoost scikit-learn相关参数
    KNN scikit-learn相关参数
    递归思想的应用-根据二叉树的中序遍历和前序遍历重建二叉树
  • 原文地址:https://www.cnblogs.com/LyShark/p/15019710.html
Copyright © 2020-2023  润新知