Check whether a driver is installed for my USB device

与世无争的帅哥 提交于 2021-01-27 09:33:26

问题


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

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


回答1:


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:

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


来源:https://stackoverflow.com/questions/11190241/check-whether-a-driver-is-installed-for-my-usb-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!