Normalmente, depois que um usuário instala um driver, uma atualização (software ou sistema) ou software, ou faz algumas alterações de configuração em uma máquina cliente ou servidor Windows, o usuário será solicitado a reinicializar o sistema. Nesta postagem, orientaremos você nas etapas de como verificar a reinicialização pendente em um computador com Windows .
Como verificar a reinicialização pendente em um computador com Windows
Após a conclusão de muitas tarefas do sistema operacional Windows, às vezes o computador é forçado a exigir uma reinicialização. Enquanto estiver conectado e em uma sessão ativa, você será notificado de que uma reinicialização está pendente ou exigida por alguma caixa pop-up ou notificação - que você pode ignorar ou aceitar para reiniciar o Windows. Mas, em algumas situações em que você não deseja ou não pode reiniciar a máquina imediatamente - por exemplo, você tem algum trabalho inacabado que precisa concluir antes de reiniciar ou acabou de instalar atualizações em um servidor de produção e esse servidor pode 't ser reiniciado imediatamente.
Em cenários como este, especialmente no que diz respeito ao último, você pode esquecer a reinicialização e, posteriormente, perceber que alguns servidores ou máquinas clientes precisam ser reinicializados, mas agora você não consegue identificar qual das máquinas - nesta situação, você pode verificar a reinicialização pendente no computador Windows usando um script do PowerShell .
Agora, quando uma reinicialização estiver pendente, o Windows adicionará alguns valores de registro ou sinalizadores para indicar isso no seguinte local de registro com os valores e condições associados, conforme mostrado na tabela abaixo.
Key | Value | Condition |
HKLM:\SOFTWARE\Microsoft\Updates | UpdateExeVolatile | Value is anything other than 0 |
HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager | PendingFileRenameOperations | value exists |
HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager | PendingFileRenameOperations2 | value exists |
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired | NA | key exists |
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending | NA | Any GUID subkeys exist |
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting | NA | key exists |
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce | DVDRebootSignal | value exists |
HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending | NA | key exists |
HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootInProgress | NA | key exists |
HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackagesPending | NA | key exists |
HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts | NA | key exists |
HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon | JoinDomain | value exists |
HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon | AvoidSpnSet | value exists |
HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName | ComputerName | Value ComputerName in HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName is different |
Como identificamos os caminhos de registro relevantes, em vez de vasculhar manualmente o registro porque você pode esquecer de verificar um caminho de registro ou simplesmente esquecer quais devem ser verificados, você pode criar e executar um script Check -PendingReboot.ps1 usando o código abaixo para automatize a tarefa para verificar todas as chaves de registro na tabela acima.
[CmdletBinding()] param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string[]]$ComputerName, [Parameter()] [ValidateNotNullOrEmpty()] [pscredential]$Credential )
$ErrorActionPreference = 'Stop'
$scriptBlock = {
$VerbosePreference = $using:VerbosePreference function Test-RegistryKey { [OutputType('bool')] [CmdletBinding()] param ( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Key ) $ErrorActionPreference = 'Stop'
if (Get-Item -Path $Key -ErrorAction Ignore) { $true } }
function Test-RegistryValue { [OutputType('bool')] [CmdletBinding()] param ( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Key,
[Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Value ) $ErrorActionPreference = 'Stop'
if (Get-ItemProperty -Path $Key -Name $Value -ErrorAction Ignore) { $true } }
function Test-RegistryValueNotNull { [OutputType('bool')] [CmdletBinding()] param ( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Key,
[Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Value ) $ErrorActionPreference = 'Stop'
if (($regVal = Get-ItemProperty -Path $Key -Name $Value -ErrorAction Ignore) -and $regVal.($Value)) { $true } }
# Added "test-path" to each test that did not leverage a custom function from above since # an exception is thrown when Get-ItemProperty or Get-ChildItem are passed a nonexistant key path $tests = @( { Test-RegistryKey -Key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending' } { Test-RegistryKey -Key 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootInProgress' } { Test-RegistryKey -Key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' } { Test-RegistryKey -Key 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackagesPending' } { Test-RegistryKey -Key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting' } { Test-RegistryValueNotNull -Key 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -Value 'PendingFileRenameOperations' } { Test-RegistryValueNotNull -Key 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -Value 'PendingFileRenameOperations2' } { # Added test to check first if key exists, using "ErrorAction ignore" will incorrectly return $true 'HKLM:\SOFTWARE\Microsoft\Updates' | Where-Object { test-path $_ -PathType Container } | ForEach-Object { (Get-ItemProperty -Path $_ -Name 'UpdateExeVolatile' | Select-Object -ExpandProperty UpdateExeVolatile) -ne 0 } } { Test-RegistryValue -Key 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce' -Value 'DVDRebootSignal' } { Test-RegistryKey -Key 'HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttemps' } { Test-RegistryValue -Key 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon' -Value 'JoinDomain' } { Test-RegistryValue -Key 'HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon' -Value 'AvoidSpnSet' } { # Added test to check first if keys exists, if not each group will return $Null # May need to evaluate what it means if one or both of these keys do not exist ( 'HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName' | Where-Object { test-path $_ } | %{ (Get-ItemProperty -Path $_ ).ComputerName } ) -ne ( 'HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName' | Where-Object { Test-Path $_ } | %{ (Get-ItemProperty -Path $_ ).ComputerName } ) } { # Added test to check first if key exists 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending' | Where-Object { (Test-Path $_) -and (Get-ChildItem -Path $_) } | ForEach-Object { $true } } )
foreach ($test in $tests) { Write-Verbose "Running scriptblock: [$($test.ToString())]" if (& $test) { $true break } } }
foreach ($computer in $ComputerName) { try { $connParams = @{ 'ComputerName' = $computer } if ($PSBoundParameters.ContainsKey('Credential')) { $connParams.Credential = $Credential }
$output = @{ ComputerName = $computer IsPendingReboot = $false }
$psRemotingSession = New-PSSession @connParams if (-not ($output.IsPendingReboot = Invoke-Command -Session $psRemotingSession -ScriptBlock $scriptBlock)) { $output.IsPendingReboot = $false } [pscustomobject]$output } catch { Write-Error -Message $_.Exception.Message } finally { if (Get-Variable -Name 'psRemotingSession' -ErrorAction Ignore) { $psRemotingSession | Remove-PSSession } } }
Você pode fornecer quantos servidores quiser por meio do parâmetro ComputerName no script, que retornará True ou False junto com o nome do servidor. Você pode executar o script semelhante ao seguinte e certificar-se de que o PowerShell Remoting esteja configurado e disponível em seus servidores.
PS51> .\Test-PendingReboot.ps1 -Server SRV1,SRV2,SRV3,etc
Usando o script do PowerShell, você pode consultar um ou todos os computadores no domínio ou fornecer manualmente os nomes dos servidores para determinar as máquinas com reinicialização pendente. Uma vez identificado, você pode reiniciar as máquinas imediatamente ou fazer uma lista para reiniciar mais tarde.
O que significa que uma reinicialização do Windows está pendente?
Geralmente, uma solicitação de reinicialização pendente ocorre quando um programa ou instalação faz uma alteração em arquivos, chaves de registro, serviços ou configurações do sistema operacional, deixando o sistema em um estado transitório. Caso você receba a notificação Uma reinicialização pendente foi detectada , ela simplesmente indica que as atualizações estão pendentes na máquina e uma reinicialização deve ser executada antes que quaisquer atualizações adicionais possam ser instaladas.
Como verificar as reinicializações pendentes no registro?
Você pode fazer isso pesquisando no Registro do Windows a chave RebootRequired . Na tabela acima nesta postagem, identificamos o local de registro relevante para chaves de registro de reinicialização pendentes. Se você quiser mostrar uma notificação quando seu PC exigir uma reinicialização para concluir a instalação de uma atualização do Windows, clique em Iniciar > Configurações > Atualização e segurança > Atualizações do Windows > Opções avançadas . Ative ou desative o botão para a opção Mostrar uma notificação quando o computador exigir uma reinicialização para concluir a atualização .