有没有办法检测Windows是否正在安装设备驱动程序?

Is there a way to detect whether Windows is installing a device driver?

情况: 我们有一个软件套件可以与我们内部构建的设备进行交互。设备使用 WinUSB 进行通信,固件更新期间处于启动模式时除外。在引导模式下,设备使用不同的 VendorID 和 ProductID,并使用 HID 进行通信。

问题: 要更新固件,我们发送命令并告诉设备进入启动模式。设备使用新的 VID 和 PID 重新枚举。在之前未连接引导模式设备的新机器上更新固件时,Windows 会在引导加载程序出现时跳 "installing driver" 舞。 (没有要安装的驱动程序)。软件收到一个 DEVICE ATTACHED 事件,因此我们开始固件更新。 Windows 完成 "installing" 驱动程序后,它会取消枚举并重新枚举设备,并在更新过程中关闭我们的文件句柄。

问题: 有没有办法检测 Windows 是否正在安装驱动程序,以便我们可以在开始更新过程之前等待设备被重新枚举?我们可以在安装中做些什么来抢占这种行为吗?也许有一种方法可以告诉 Windows 我们不想在连接到设备时安装驱动程序?

Maybe a way to tell Windows that we don't want to allow driver installation while we're connected to the device?

Microsoft 的开发人员网络有一个硬件开发部分。他们有一篇文章 specifically about this issue。重要的是,文档指出您的设备安装应用程序应该 "determine whether other installation activities are in progress before performing its installations"(强调我的)并且 - 如果找到待处理的安装 - "should exit"。

声明的最后一部分似乎表明 Microsoft 优先考虑已安装或待处理 设备应用程序安装。

如果你的问题陈述是准确的:

When updating firmware on a new machine that hasn't had a device in boot mode connected before, Windows does the "installing driver" dance when the bootloader shows up.

听起来您可能不走运 - 或者违反惯例 - 试图抢占驱动程序安装行为。

我会利用上面提到的 CMP_WaitNoPendingInstallEvents function, and then firmware update your device. I think the VID/PID are irrelevant, here, depending upon where your firmware update code is running. It looks like the OSR Online Forum has a question of the same nature 并假定相同的优先级(驱动程序安装)。