mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2025-11-17 11:06:18 +00:00
Add time-out to System Restore Point creation #289
This commit is contained in:
@@ -782,6 +782,7 @@ function CreateSystemRestorePoint {
|
||||
|
||||
if ($SysRestore.RPSessionInterval -eq 0) {
|
||||
if ($Silent -or $( Read-Host -Prompt "System restore is disabled, would you like to enable it and create a restore point? (y/n)") -eq 'y') {
|
||||
$enableSystemRestoreJob = Start-Job {
|
||||
try {
|
||||
Enable-ComputerRestore -Drive "$env:SystemDrive"
|
||||
} catch {
|
||||
@@ -789,12 +790,24 @@ function CreateSystemRestorePoint {
|
||||
Write-Output ""
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
$enableSystemRestoreJobDone = $enableSystemRestoreJob | Wait-Job -TimeOut 20
|
||||
|
||||
if (-not $enableSystemRestoreJobDone) {
|
||||
Write-Host "Error: Failed to enable system restore and create restore point, operation timed out" -ForegroundColor Red
|
||||
Write-Output ""
|
||||
Write-Output "Press any key to continue anyway..."
|
||||
$null = [System.Console]::ReadKey()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
Write-Output ""
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
$createRestorePointJob = Start-Job {
|
||||
# Find existing restore points that are less than 24 hours old
|
||||
try {
|
||||
$recentRestorePoints = Get-ComputerRestorePoint | Where-Object { (Get-Date) - [System.Management.ManagementDateTimeConverter]::ToDateTime($_.CreationTime) -le (New-TimeSpan -Hours 24) }
|
||||
@@ -814,6 +827,16 @@ function CreateSystemRestorePoint {
|
||||
} else {
|
||||
Write-Host "A recent restore point already exists, no new restore point was created." -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
|
||||
$createRestorePointJobDone = $createRestorePointJob | Wait-Job -TimeOut 20
|
||||
|
||||
if (-not $createRestorePointJobDone) {
|
||||
Write-Host "Error: Failed to create system restore point, operation timed out" -ForegroundColor Red
|
||||
Write-Output ""
|
||||
Write-Output "Press any key to continue anyway..."
|
||||
$null = [System.Console]::ReadKey()
|
||||
}
|
||||
|
||||
Write-Output ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user