Question

I manually install my driver using an .inf file. Until now, I deleted the oem.inf and .pnf files from the inf folder to uninstall. Whenever I install a new driver I delete/uninstall the old inf and pnf files.

In my old uninstalls (by deleting .inf and .pnf files), I didn't modify or delete any registry settings.

In this case do I want to change or remove any settings from the registry (for example: devnode)?

Was it helpful?

Solution

You should use the SetupUninstallOEMInf function to uninstall the .INF (and subsequently .PNF) files. This will take care of the details. pnputil (on Vista and higher) should do the equivalent thing from the command line. However, this function will not delete drivers that are currently installed (e.g. associated with a devnode).

  1. Why are you uninstalling the old driver first? The user might already installed your driver for at least one devnode. Why not use a Microsoft-sanctioned solution such as DpInst? It will do the work required to update the driver.

  2. Passing SUOI_FORCEDELETE to SetupUninstallOEMInf wouldn't be a good idea, cause you'd end up with lingering .INF references in your devnodes (in the registry).

  3. At work I wrote a utility I called DriverUninstaller that deletes the devnodes and then deleted the INFs. I only use this utility for uninstallations. Upgrades are handled by DpInst, as they should be. The flow is roughly:

    1. Enumerate them with SetupAPI (e.g. by device class if your device class is unique)
    2. For each devnode, call SetupDiCallClassInstaller(DIF_REMOVE, ...)
    3. Call SetupDiBuildDriverInfoList to find all .INF files for my device
    4. For each INF, call SetupUninstallOEMInf

If there'll be interest in this utility, I might be able to persuade my employer to open-source it :-)

OTHER TIPS

As the other answer points out the API to remove drivers on Windows is the SetupUninstallOEMInf method but I figured I'd add a few important notes here:

  • the INF path parameter must be the file name only (must not include the full path!)
  • this API requires Administrator privileges (this is not much of a surprise)
  • on 64-bit systems, the method only works when executed in the context of a 64-bit process (ie. WOW64 doesn't work)

The SetupDiGetDriverInfoDetail API can be used to query information about the relevant INF file(s) to remove for a particular device. And the SetupDiEnumDriverInfo/SetupDiBuildDriverInfoList APIs can be used to enumerate all drivers for a particular device.

  // given infFilePath - full path to inf as returned by a query using SetupDiGetDriverInfoDetail
  TCHAR* infFileName = GetFileNamePart(infFilePath);
  if(SetupUninstallOEMInf(pInf, SUOI_FORCEDELETE, NULL))
  {
       // success
  }else
  {
DWORD errCode = GetLastError();
if(errCode == 0x02)
{
            //  means that the driver INF file was not found
            //  most likely it was already uninstalled 
}else if(errCode == 0x05)
      {
            //  must run as administrator
      }else
{
           // some other error code.. handle appropriately
}
  }

I've open-sourced the code for a tool I wrote to perform driver uninstalls for USB and Media/Image devices. Details here: http://mdinescu.com/software-development/30-driver-hunter-programatically-uninstall-drivers-in-windows

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top