public override bool DeviceFound(DeviceItem item, IntPtr pDeviceInfoSet, ref SetupApi.SP_DEVINFO_DATA DeviceInfoData) { if (mRemoveDeviceOptions.RemoveByVidPid) { if (item.VendorID.ToLower() != mRemoveDeviceOptions.DeviceItem.VendorID.ToLower() || item.ProductID.ToLower() != mRemoveDeviceOptions.DeviceItem.ProductID.ToLower()) { return(true); } } else { if (item.mDeviceId != mRemoveDeviceOptions.DeviceItem.mDeviceId) { return(true); } } bool bUninstalled; if (SetupApi.WindowsVersion >= WindowsVersionType.WINDOWS_7) { if ((bUninstalled = SetupApi.DiUninstallDevice(IntPtr.Zero, pDeviceInfoSet, ref DeviceInfoData, 0, IntPtr.Zero)) == true) { mRemoved++; } else { InfWizardStatus.Log(CategoryType.RemoveDevice, StatusType.Warning | StatusType.Win32Error, "failed uninstalling device."); } } else { if ((bUninstalled = SetupApi.SetupDiRemoveDevice(pDeviceInfoSet, ref DeviceInfoData)) == true) { mRemoved++; } else { InfWizardStatus.Log(CategoryType.RemoveDevice, StatusType.Warning | StatusType.Win32Error, "failed uninstalling device."); } } if (bUninstalled) { InfWizardStatus.Log(CategoryType.RemoveDevice, StatusType.Success, "device uninstall complete"); } object oInfFileName; if (item.mDriverRegistryList != null && !item.mIsSkipServiceName) { if (item.mDriverRegistryList.TryGetValue("InfPath", out oInfFileName)) { if (!(SetupApi.SetupUninstallOEMInf(oInfFileName.ToString(), SetupApi.SUOI.FORCEDELETE, IntPtr.Zero))) { InfWizardStatus.Log(CategoryType.RemoveDevice, StatusType.Warning | StatusType.Win32Error, "SetupUninstallOEMInf failed"); } } } return(mRemoveDeviceOptions.RemoveByVidPid); }
public Boolean Uninstall() { using (SafeDeviceInfoSetHandle dis = SetupApi.SetupDiGetClassDevsA(IntPtr.Zero, DeviceID, IntPtr.Zero, DICFG.DEVICEINTERFACE | DICFG.ALLCLASSES)) { if (dis.IsInvalid) { throw new Win32Exception(); } SP_DEVINFO_DATA dd = new SP_DEVINFO_DATA(true); if (!SetupApi.SetupDiEnumDeviceInfo(dis, 0, ref dd)) { throw new Win32Exception(); } Boolean needsReboot; if (!SetupApi.DiUninstallDevice(IntPtr.Zero, dis, ref dd, 0, out needsReboot)) { throw new Win32Exception(); } return(needsReboot); } }