我有一项服务在启动时进行了一些系统配置,但遇到了一个问题,即 Windows 更新同时运行并启动了重新启动,这中断了我的服务正在执行的操作,并且我的配置被破坏了。我想将服务启动延迟到 Windows 更新完成并完成任何重新启动之后。有没有办法告诉更新当前正在运行?然后我可以让我的服务等待并在下次启动或更新完成时恢复。将我的服务标记为自动(延迟启动)是否有帮助?
编辑:我严格控制是否启用/禁用 Windows 更新服务,作为配置的一部分,我手动启用服务并安装特定更新。通常这会导致错误代码 3010,这意味着需要重新启动机器并完成更新。因此,在重新启动后,我会从我的服务中继续进行进一步的配置更新。
经过进一步调查,这是由于 Windows 更新启动失败而发生的。我在 CBS 日志中看到了这一点:
2020-03-26 21:05:54, Info CBS Startup: Failed, restart required to try again.
2020-03-26 21:05:54, Info CBS Startup: Processing complete. [HRESULT = 0x80070bc2 - ERROR_SUCCESS_REBOOT_REQUIRED]
2020-03-26 21:05:54, Info CBS Keeping Trusted Installer as auto-start
2020-03-26 21:05:54, Info CBS Winlogon: Checking to see if CreateSessionNotify has been called at least once.
2020-03-26 21:05:54, Info CBS Winlogon: CreateSessionNotify has been called
2020-03-26 21:05:54, Info CBS Winlogon: Simplifying Winlogon CreateSession notifications
2020-03-26 21:05:54, Info CBS Startup: received notification that startup processing completed and a restart has been initiated.
2020-03-26 21:05:54, Info CBS A restart has been initiated
之后我的服务重新启动了机器并恢复了其配置,但 Windows 更新随后同时运行并重新启动了我。在另一台机器上这没有发生,我在 CBS 日志中有这些消息:
2020-03-26 21:01:50, Info CBS Startup: Retrying failed packages.
2020-03-26 21:01:50, Info CBS Startup: Processing complete. [HRESULT = 0x00000000 - S_OK]
2020-03-26 21:01:50, Info CBS Enabling LKG boot option
2020-03-26 21:01:50, Info CBS Setting ServicingInProgress flag to 0
2020-03-26 21:01:50, Info CBS Startup processing completed. [HRESULT = 0x00000000]
2020-03-26 21:01:50, Info CBS Winlogon: Simplifying Winlogon CreateSession notifications
2020-03-26 21:01:50, Info CBS Winlogon: Deregistering for CreateSession notifications
2020-03-26 21:01:50, Info CBS Startup: received notification that startup processing completed, allowing user to logon
2020-03-26 21:01:50, Info CBS Startup processing complete, Trusted Installer will now wait around for a little while to see if any clients show up.
我不确定如何区分这两种情况,Windows Update 已完成并需要重新启动,以及它本质上将重新启动并重试,而不是解析此日志。我正在寻找某种状态或状态来指示 Windows 更新正在做什么。