Com comprovar si hi ha un reinici pendent a l'ordinador Windows

Com Comprovar Si Hi Ha Un Reinici Pendent A L Ordinador Windows



Normalment, després que un usuari instal·li un controlador, una actualització (programari o sistema) o programari, o faci alguns canvis de configuració en una màquina client o servidor de Windows, se li demanarà a l'usuari que reiniciï el sistema. En aquesta publicació, us explicarem els passos sobre com fer-ho comproveu Pending Reboot en un ordinador Windows .



  Com comprovar si hi ha un reinici pendent a l'ordinador Windows





Com comprovar si hi ha un reinici pendent en un ordinador Windows

En completar moltes tasques del sistema operatiu Windows, de vegades l'ordinador es veu obligat a requerir un reinici. Mentre inicieu sessió i en una sessió activa, se us notificarà que un reinici està pendent o requerit per algun quadre emergent o notificació, que podeu descartar o acceptar per reiniciar Windows. Però, en algunes situacions en què no voleu o no podeu reiniciar immediatament la màquina; per exemple, teniu una feina sense acabar que heu de completar abans de reiniciar, o acabeu d'instal·lar actualitzacions en un servidor de producció i aquest servidor pot no es reiniciï immediatament.





Les finestres explorer.exe no poden accedir al dispositiu especificat

En escenaris com aquest, sobretot pel que fa a aquest últim, és possible que us oblideu del reinici i més endavant us adoneu que cal reiniciar alguns servidors o màquines client, però ara no podeu identificar quina de les màquines, en aquesta situació, podeu comprovar si hi ha un reinici pendent a l'ordinador Windows mitjançant un PowerShell guió.



Ara, quan estigui pendent un reinici, Windows afegirà alguns valors o senyaladors de registre per indicar-ho a la següent ubicació del registre amb els valors i condicions associats, tal com es mostra a la taula següent.

clau Valor Condició
HKLM:\SOFTWARE\Microsoft\Actualitzacions UpdateExeVolatile El valor és qualsevol cosa que no sigui 0
HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager PendingFileRenameOperations el valor existeix
HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager PendingFileRenameOperations2 el valor existeix
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired AIXÒ la clau existeix
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending AIXÒ Hi ha qualsevol subclau GUID
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting AIXÒ la clau existeix
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce DVDRebootSignal el valor existeix
HKLM:\Software\Microsoft\Windows\CurrentVersion\Serveig basat en components\RebootPending AIXÒ la clau existeix
HKLM:\Software\Microsoft\Windows\CurrentVersion\Serveig basat en components\RebootInProgress AIXÒ la clau existeix
HKLM:\Software\Microsoft\Windows\CurrentVersion\Serveig basat en components\PackagesPending AIXÒ la clau existeix
HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts AIXÒ la clau existeix
HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon JoinDomain el valor existeix
HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon AvoidSpnSet el valor existeix
HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName Nom de l'ordinador El valor ComputerName a HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName és diferent

Com que hem identificat els camins de registre rellevants, en lloc de revisar manualment el registre perquè és possible que oblideu de comprovar un camí de registre o simplement oblideu quins heu de comprovar, podeu crear i executar un script Check-PendingReboot.ps1 que utilitza el codi següent per automatitzar la tasca per comprovar totes les claus de registre de la taula anterior.

  Creeu i executeu un script de PowerShell



[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
}
}
}

Podeu proporcionar tants servidors com vulgueu mitjançant el Nom de l'ordinador paràmetre de l'script que tornarà És cert o Fals juntament amb el nom del servidor. Podeu executar l'script de manera similar al següent i assegureu-vos PowerShell Remoting està configurat i disponible als vostres servidors.

PS51> .\Test-PendingReboot.ps1 -Server SRV1,SRV2,SRV3,etc

Llegeix : Com programar l'script de PowerShell al Programador de tasques

Mitjançant l'script de PowerShell, podeu consultar un o tots els ordinadors del domini o proporcionar manualment els noms del servidor per determinar les màquines pendents de reiniciar. Un cop identificats, podeu reiniciar les màquines immediatament o fer una llista per reiniciar més tard.

Ara llegiu : Com reiniciar remotament l'ordinador Windows amb PowerShell

powershell obté actualitzacions instal·lades

Què vol dir que el reinici de Windows està pendent?

En general, es produeix una sol·licitud de reinici pendent quan un programa o una instal·lació fa un canvi als fitxers, les claus del registre, els serveis o la configuració del sistema operatiu que pot deixar el sistema en un estat transitori. En el cas que obtingueu el S'ha detectat un reinici pendent notificació, simplement indica que hi ha actualitzacions pendents a la màquina i s'ha de reiniciar abans que es pugui instal·lar cap actualització addicional.

Llegeix :

  • Com desactivar o habilitar la notificació de reinici de l'actualització
  • Actualització de Windows Pendent d'instal·lació o descàrrega, inicialització, etc

Com comprovar els reinicis pendents al registre?

Pots fer-ho mitjançant cercant al Registre de Windows per al Cal reiniciar clau. A la taula anterior d'aquesta publicació, hem identificat la ubicació del registre rellevant per a les claus del registre de reinici pendents. Si voleu mostrar una notificació quan el vostre PC requereixi un reinici per completar una instal·lació d'actualització de Windows, feu clic a Començar > Configuració > Actualització i seguretat > Actualitzacions de Windows > Opcions avançades . Activa o desactiva el botó per a Mostra una notificació quan el teu PC requereix un reinici per acabar d'actualitzar-se opció.

Llegeix també : Hi ha una reparació del sistema pendent que requereix un reinici per completar-se .

Entrades Populars