Exemplo n.º 1
0
        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);
        }