Microsoft KB Archive/822445

= How To Make Sure That a Service is Removed When The Driver is Uninstalled or Upgraded =

Article ID: 822445

Article Last Modified on 8/30/2004

-

APPLIES TO


 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Professional Edition
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows XP Professional

-



SUMMARY
This article, and the sample code contained herein, explains a technique to make sure that a service that is associated with your driver is removed when you install or upgrade the driver.



MORE INFORMATION
The driver writer can handle removal of associated services in their device coInstaller by handling the Dif_DestroyPrivateData function: HKEY hKey; BOOL bNeedToUninstallService = FALSE;

switch(InstallFunction) {

case DIF_DESTROYPRIVATEDATA :

//       // If the co-installer is being unloaded, and is no longer in the list of        // device-specific co-installers for this device, then the driver is        // being replaced (or the device is being uninstalled altogether). //       hKey = SetupDiOpenDevRegKey(DeviceInfoSet,                                    DeviceInfoData,                                    DICS_FLAG_GLOBAL,                                    0,                                    DIREG_DRV,                                    KEY_READ                                   );

if(hKey == INVALID_HANDLE_VALUE) { //           // If you cannot open the key for read access, this most likely // means that the device's driver key has been deleted (typically,           // because the device is being uninstalled). Therefore, treat this // the same as the scenario where the co-installer is no longer in            // the list. //           bNeedToUninstallService = TRUE;

} else { //           // Retrieve the REG_MULTI_SZ list of co-installers from the // CoInstallers32 value entry, and then look for the co-installer // module/entry-point in the list. //           bNeedToUninstallService = !CoinstallerStillInList(hKey, &quot;CoInstallers32&quot;);

RegCloseKey(hKey); }

if(bNeedToUninstallService) {

 }

return NO_ERROR; }



Keywords: kbhowto KB822445

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.