SetupDiGetDeviceRegistryProperty-使用SetupDi系列函数进行设备信息的管理(三)

WINSETUPAPI BOOL WINAPI
  SetupDiGetDeviceRegistryProperty(
    IN HDEVINFO  DeviceInfoSet,
    IN PSP_DEVINFO_DATA  DeviceInfoData,
    IN DWORD  Property,
    OUT PDWORD  PropertyRegDataType,  OPTIONAL
    OUT PBYTE  PropertyBuffer,
    IN DWORD  PropertyBufferSize,
    OUT PDWORD  RequiredSize  OPTIONAL
    );

SetupDiGetDeviceRegistryProperty:获得单个装置的详细资料

参数说明:

DeviceInfoSet

设备信息句柄

DeviceInfoData

SP_DEVINFO_DATA结构体,包含DeviceInfoSet 中的设备信息

Property

    取以下的值:

SPDRP_ADDRESS

查询设备的地址

SPDRP_BUSNUMBER

查询设备的bus号

SPDRP_BUSTYPEGUID

查询设备的GUID号

SPDRP_CAPABILITIES

The function retrieves a bitwise OR of the following CM_DEVCAP_Xxx flags in a DWORD. The device capabilities that are represented by these flags correspond to the device capabilities that are represented by the members of the DEVICE_CAPABILITIES structure. The CM_DEVCAP_Xxx constants are defined in cfgmgr32.h.

CM_DEVCAP_Xxx flag Corresponding DEVICE_CAPABILITIES structure member
CM_DEVCAP_LOCKSUPPORTED LockSupported
CM_DEVCAP_EJECTSUPPORTED EjectSupported
CM_DEVCAP_REMOVABLE
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要读取 Windows 设备管理器中的所有驱动信息,可以使用 Windows API 提供的 SetupDi 系列函数。下面是一个简单的 C++ 代码示例,可以列出所有已安装的驱动程序名称和供应商: ```c++ #include <Windows.h> #include <SetupAPI.h> #include <iostream> #pragma comment(lib, "setupapi.lib") int main() { HDEVINFO deviceInfo; SP_DEVINFO_DATA deviceInfoData; DWORD index; CHAR deviceName[1024], vendorName[1024]; deviceInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT); if (deviceInfo == INVALID_HANDLE_VALUE) { std::cerr << "Failed to get device information" << std::endl; return 1; } deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); for (index = 0; SetupDiEnumDeviceInfo(deviceInfo, index, &deviceInfoData); index++) { DWORD propertyType; DWORD requiredSize; // 获取设备名称 if (!SetupDiGetDeviceRegistryPropertyA(deviceInfo, &deviceInfoData, SPDRP_DEVICEDESC, &propertyType, reinterpret_cast<PBYTE>(deviceName), sizeof(deviceName), &requiredSize)) { std::cerr << "Failed to get device name" << std::endl; continue; } // 获取供应商名称 if (!SetupDiGetDeviceRegistryPropertyA(deviceInfo, &deviceInfoData, SPDRP_MFG, &propertyType, reinterpret_cast<PBYTE>(vendorName), sizeof(vendorName), &requiredSize)) { std::cerr << "Failed to get vendor name" << std::endl; continue; } std::cout << "Device: " << deviceName << std::endl; std::cout << "Vendor: " << vendorName << std::endl; std::cout << std::endl; } SetupDiDestroyDeviceInfoList(deviceInfo); return 0; } ``` 该程序调用了 SetupDiGetClassDevs 函数获取设备信息列表的句柄,然后通过 SetupDiEnumDeviceInfo 函数枚举设备信息。对于每个设备,它调用 SetupDiGetDeviceRegistryProperty 函数来获取设备名称和供应商名称,并将结果输出到控制台。 需要注意的是,此代码需要在 Windows 环境下编译和运行,并且需要使用 Visual Studio 或其他支持 Windows API 的 C++ 编译器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值