public static bool InstallSetupPackage(string hardwareId, string infPath) { bool bSuccess = SetupApi.UpdateDriverForPlugAndPlayDevices(IntPtr.Zero, hardwareId, infPath, SetupApi.INSTALLFLAG.FORCE, IntPtr.Zero); if (bSuccess) { InfWizardStatus.Log(CategoryType.InstallSetupPackage, StatusType.Success, "driver update completed"); UpdateDriver(hardwareId); return(true); } // UpdateDriverForPlugAndPlayDevices FAILED ECODE setupError = (ECODE)Marshal.GetLastWin32Error(); if (setupError != ECODE.NO_SUCH_DEVINST) { InfWizardStatus.Log(CategoryType.InstallSetupPackage, StatusType.Win32Error, "UpdateDriverForPlugAndPlayDevices failed"); return(false); } // UpdateDriverForPlugAndPlayDevices = NO_SUCH_DEVINST InfWizardStatus.Log(CategoryType.InstallSetupPackage, StatusType.Warning, "device not detected (copying driver files for next time device is plugged in)"); StringBuilder sbDestInfFilename = new StringBuilder(1024); uint requiredSize; bSuccess = SetupApi.SetupCopyOEMInf(infPath, null, SetupApi.SPOST.SPOST_PATH, 0, sbDestInfFilename, (uint)sbDestInfFilename.Capacity, out requiredSize, null); if (!bSuccess) { InfWizardStatus.Log(CategoryType.InstallSetupPackage, StatusType.Win32Error, "SetupCopyOEMInf failed"); } else { InfWizardStatus.Log(CategoryType.InstallSetupPackage, StatusType.Success, "copied inf to {0}", sbDestInfFilename.ToString()); } CheckRemoved(hardwareId); return(bSuccess); }