查注册表判断是否有待重启操作

检测更新或安装是否在等一次重启——“重启一下就好了”的真正原因。

Windows更新重启PowerShell低风险
用 Test-Path 检查上面列出的 RebootRequired / RebootPending 注册表键,任意存在即说明需要重启才能完成变更。

01命令

命令
$ $keys = @(
  'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired',
  'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending',
  'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackagesPending')
$keys | Where-Object { Test-Path $_ }

02作用说明

许多更新、驱动安装和 .NET/DISM 操作会先暂存变更,到下次开机才真正完成,期间会在注册表留下标记键——处于这种状态的机器行为难以预料(服务启动失败、文件被占用、设置改了又弹回)。三个经典位置是 WindowsUpdate 的 RebootRequired、组件服务(CBS)的 RebootPending/PackagesPending,部分 MSI 安装还会用 HKLM:\SOFTWARE\Microsoft\Updates 的 UpdateExeVolatile。上面的一行命令会报告哪些标记存在;社区模块 PendingReboot 封装了包括 PendingFileRenameOperations 在内的完整检测,适合批量管理。重启即可清除这些标记——没有“取消”待重启的正规办法,只能完成重启。

03风险

风险低风险
!注意: 不要直接删除这些注册表键来伪装干净状态:暂存的变更会在下次开机时以半成品状态生效,风险很大。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • PendingReboot module
    PowerShell Gallery · community · 2026-09-17
    依据: Documents the well-known pending-reboot registry locations (WindowsUpdate RebootRequired, Component Based Servicing RebootPending/PackagesPending) and packages them into a test module.

最后验证: 2026-09-18 · 分类: 系统与设置

06相关方案