Using SetupAPI to Uninstall Devices and Driver Packages
SetupAPI is a system component that provides two sets of functions:
Device installation applications, co-installers, and class installers can use these functions to perform custom operations for device installation. SetupAPI also supports uninstalling the devices and driver packages that it installs.
This topic describes the procedures that you can follow to uninstall devices and driver packages by using the SetupAPI functions.
For more information about uninstalling driver and driver packages, see How Devices and Driver Packages are Uninstalled.
A device installation application can request that a device be uninstalled by calling the SetupDiCallClassInstaller function. When the application calls this function to uninstall a device, it must set the InstallFunction parameter to the DIF_REMOVE code. For a list of all DIF codes, see Device Installation Functions.
If SetupDiRemoveDevice is called during the processing of the DIF_REMOVE request, the function removes the device's devnode from the system. It also deletes the device's hardware and software registry keys, together with any hardware-profile-specific registry keys (configuration-specific registry keys).
Note SetupDiRemoveDevice must only be called by a class installer and not by a device installation application.
For more information about DIF codes, see Handling DIF Codes.
Starting with Windows 7, a device installation application can uninstall a device by calling the DiUninstallDevice function. This function is similar to calling SetupDiCallClassInstaller with the InstallFunction parameter set to DIF_REMOVE. However, in addition to removing the devnode of the specified device, this function attempts to remove all child devnodes of the device that are present on the system at the time of the call.
SetupAPI cannot be used to perform this action.