mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-02-17 07:56:24 +00:00
Prompt after failure to create restore point (#469)
This commit is contained in:
@@ -3387,6 +3387,7 @@ function ExecuteAllChanges {
|
||||
|
||||
function CreateSystemRestorePoint {
|
||||
$SysRestore = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name "RPSessionInterval"
|
||||
$failed = $false
|
||||
|
||||
if ($SysRestore.RPSessionInterval -eq 0) {
|
||||
# In GUI mode, skip the prompt and just try to enable it
|
||||
@@ -3406,23 +3407,24 @@ function CreateSystemRestorePoint {
|
||||
if (-not $enableSystemRestoreJobDone) {
|
||||
Remove-Job -Job $enableSystemRestoreJob -Force -ErrorAction SilentlyContinue
|
||||
Write-ToConsole "Error: Failed to enable system restore and create restore point, operation timed out" -ForegroundColor Red
|
||||
return
|
||||
$failed = $true
|
||||
}
|
||||
else {
|
||||
$result = Receive-Job $enableSystemRestoreJob
|
||||
Remove-Job -Job $enableSystemRestoreJob -ErrorAction SilentlyContinue
|
||||
if ($result) {
|
||||
Write-ToConsole $result -ForegroundColor Red
|
||||
return
|
||||
$failed = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-ToConsole ""
|
||||
return
|
||||
$failed = $true
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $failed) {
|
||||
$createRestorePointJob = Start-Job {
|
||||
# Find existing restore points that are less than 24 hours old
|
||||
try {
|
||||
@@ -3442,7 +3444,7 @@ function CreateSystemRestorePoint {
|
||||
}
|
||||
}
|
||||
else {
|
||||
return @{ Success = $true; Message = "A recent restore point already exists, no new restore point was created"; Warning = $true }
|
||||
return @{ Success = $true; Message = "A recent restore point already exists, no new restore point was created" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3451,24 +3453,48 @@ function CreateSystemRestorePoint {
|
||||
if (-not $createRestorePointJobDone) {
|
||||
Remove-Job -Job $createRestorePointJob -Force -ErrorAction SilentlyContinue
|
||||
Write-ToConsole "Error: Failed to create system restore point, operation timed out" -ForegroundColor Red
|
||||
$failed = $true
|
||||
}
|
||||
else {
|
||||
$result = Receive-Job $createRestorePointJob
|
||||
Remove-Job -Job $createRestorePointJob -ErrorAction SilentlyContinue
|
||||
if ($result.Success) {
|
||||
if ($result.Warning) {
|
||||
Write-ToConsole $result.Message -ForegroundColor Yellow
|
||||
}
|
||||
else {
|
||||
Write-ToConsole $result.Message
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-ToConsole $result.Message -ForegroundColor Red
|
||||
$failed = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Ensure that the user is aware if creating a restore point failed, and give them the option to continue without a restore point or cancel the script
|
||||
if ($failed) {
|
||||
if ($script:GuiConsoleOutput) {
|
||||
$result = [System.Windows.MessageBox]::Show(
|
||||
'Failed to create a system restore point. Do you want to continue without a restore point?',
|
||||
'Restore Point Creation Failed',
|
||||
[System.Windows.MessageBoxButton]::YesNo,
|
||||
[System.Windows.MessageBoxImage]::Warning
|
||||
)
|
||||
|
||||
if ($result -ne [System.Windows.MessageBoxResult]::Yes) {
|
||||
$script:CancelRequested = $true
|
||||
return
|
||||
}
|
||||
}
|
||||
elseif (-not $Silent) {
|
||||
Write-ToConsole "Failed to create a system restore point. Do you want to continue without a restore point? (y/n)" -ForegroundColor Yellow
|
||||
if ($( Read-Host ) -ne 'y') {
|
||||
$script:CancelRequested = $true
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Write-ToConsole "Warning: Continuing without restore point" -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function ShowScriptMenuOptions {
|
||||
Do {
|
||||
|
||||
Reference in New Issue
Block a user