检查是否为我的USB设备安装了驱动程序 [英] Check whether a driver is installed for my USB device

查看:75
本文介绍了检查是否为我的USB设备安装了驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了 SetupDiGetClassDevs() SetupDiEnumDeviceInfo() SetupDiGetDeviceRegistryProperty()来枚举我的USB设备并检查我的设备是否可用或不是.

I used SetupDiGetClassDevs(), SetupDiEnumDeviceInfo() and SetupDiGetDeviceRegistryProperty() to enumerate my USB device and check whether my device is available or not.

如何检查我的设备是否安装了正确的驱动程序?
有没有可用的API可以对此进行检查?

How can I check whether my proper driver is installed for my device or not?
Is there any APIs available to check this?

推荐答案

您可以获取设备的驱动程序信息,然后根据驱动程序信息进行检查(如果您的驱动程序已安装并且是最新数据).

You can get the driver information for the device and then check against that, if your driver is installed and up-to-data.

以下是一些C ++代码,可能会帮助您:

Here is a bit of C++ code which might help you:

bool fetchDriverDescription( const std::wstring& driverRegistryLocation, tDriverDescription& desc )
{
    bool    rval = false;

    std::wstring regFolder = L"SYSTEM\\CurrentControlSet\\Control\\Class\\";
    regFolder += driverRegistryLocation;
    win32::registry::reg_key hKey = 
        win32::registry::reg_key::open( HKEY_LOCAL_MACHINE, regFolder, KEY_READ );
    if( hKey )
    {
        if( win32::registry::read( hKey, L"ProviderName", desc.DriverProviderName, false ) != ERROR_SUCCESS )
            return false;

        desc.InstalledDriverRegFolder = regFolder;

        std::wstring val;
        if( win32::registry::read( hKey, L"DriverVersion", val, false ) == ERROR_SUCCESS )
            desc.Version = val;
        rval = true;
    }
    return rval;
}

std::wstring driverRegLocation;
if( fetchStringFromDiGetDevice( hDevInfo, DeviceInfo, SPDRP_DRIVER, driverRegLocation ) )
{
    bSuccessful = fetchDriverDescription( driverRegLocation, dev.DriverDesc );
}

这篇关于检查是否为我的USB设备安装了驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆