2vision2
2vision2

Reputation: 5023

Remove oem.inf files corresponding to hardware id

I'm installing my driver using dpinst.exe. But before installing my driver I wish to delete all the oem files from inf directory corresponding to my hardware ID.

I want to do this programatically. Please suggest me a way to do this.

**Update :**

I want to do this without device connected as I may pre-install the driver before connecting the device. My device is PNP device.

Upvotes: 1

Views: 4320

Answers (2)

pcfist
pcfist

Reputation: 169

PhilMY has already posted an excellent answer, which is still relevant. However, it is more than ten years old now, so I wanted to update it with more recent/recommended APIs:

  1. Use SetupDiEnumDeviceInfo() and SetupDiGetDeviceRegistryProperty() to match your hardware ID
  2. To get the OEM INF path, SetupDiGetDriverInfoDetail() can be used instead of reading the registry directly
  3. Call DiUninstallDriver() on the resulting INF path (Microsoft recommends using it instead of SetupUninstallOEMInf(). In addition, it returns the needReboot flag, which may be useful in some scenarios.)

#2 is a little tricky as it requires SP_DRVINFO_DATA on input. To acquire it, one typically needs to call SetupDiBuildDriverInfoList() and SetupDiEnumDriverInfo() to iterate through all installed drivers for a particular device (use SPDIT_COMPATDRIVER flag to enumerate 3rd-party drivers).

It has a significant advantage in scenarios when multiple drivers are suitable for the given device, and this approach allows one to choose exactly which driver to uninstall.

Upvotes: 1

PhilMY
PhilMY

Reputation: 2651

  1. Use SetupDiEnumDeviceInfo and SetupDiGetDeviceRegistryProperty to match your hardware ID
  2. Use SetupDiOpenDevRegKey and RegQueryValueEx to read the corresponding InfPath
  3. Call SetupUninstallOEMInf

Upvotes: 2

Related Questions