检查我的USB设备是否安装了驱动程序

时间:2021-07-10 07:20:53

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

我使用SetupDiGetClassDevs()、SetupDiEnumDeviceInfo()和SetupDiGetDeviceRegistryProperty()来枚举我的USB设备,并检查我的设备是否可用。

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

如何检查设备是否安装了合适的驱动程序?有可用的api来检查这个吗?

1 个解决方案

#1


3  

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

您可以获取设备的驱动程序信息,然后检查是否安装了驱动程序并提供最新数据。

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

这里有一些c++代码可以帮助您:

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 );
}

#1


3  

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

您可以获取设备的驱动程序信息,然后检查是否安装了驱动程序并提供最新数据。

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

这里有一些c++代码可以帮助您:

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 );
}