我试图以编程方式获取驱动程序的版本号.似乎是通过使用SetupDiEnumDriverInfo
获取SP_DRVINFO_DATA
结构并检查它来完成的DriverVersion field
.
以下代码有效,但为同一驱动程序返回两个不同的版本.我的设备是一个自定义USB设备,带有一个.sys文件.我的机器只连接了一台设备.我指定DIGCF_PRESENT
只查询当前连接的设备的驱动程序.
int main(void)
{
// Get the "device info set" for our driver GUID
HDEVINFO devInfoSet = SetupDiGetClassDevs(
&GUID_DEVINTERFACE_USBSPI, NULL, NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
// Cycle through all devices currently present
for (int i = 0; ; i++)
{
// Get the device info for this device
SP_DEVINFO_DATA devInfo;
devInfo.cbSize = sizeof(SP_DEVINFO_DATA);
if (!SetupDiEnumDeviceInfo(devInfoSet, i, &devInfo))
break;
// Build a list of driver info items that we will retrieve below …
Run Code Online (Sandbox Code Playgroud)