Add check to see if System Restore is enabled, with option to enable it (#235)

Co-authored-by: Lucas <100943586+lucas-timeworkstudio@users.noreply.github.com>
This commit is contained in:
Jeffrey
2025-05-05 22:47:31 +02:00
committed by GitHub
parent 7de3ba2751
commit 09b4eb7f6b

View File

@@ -743,7 +743,26 @@ function GetUserName {
function CreateSystemRestorePoint {
Write-Output "> Creating system restore point..."
Write-Output "> Attempting to create a system restore point..."
$SysRestore = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name "RPSessionInterval"
if ($SysRestore.RPSessionInterval -eq 0) {
if (-not $Silent) {
if ($( Read-Host -Prompt "System restore is disabled, would you like to enable it and create a restore point? (y/n)") -eq 'y') {
try {
Enable-ComputerRestore -Drive "$env:SystemDrive"
} catch {
Write-Host "Error: Failed to enable System Restore: $_" -ForegroundColor Red
Write-Output ""
return
}
} else {
Write-Output ""
return
}
}
}
# Find existing restore points that are less than 24 hours old
try {
@@ -760,10 +779,8 @@ function CreateSystemRestorePoint {
Write-Output "System restore point created successfully"
} catch {
Write-Host "Error: Unable to create restore point: $_" -ForegroundColor Red
return
}
}
else {
} else {
Write-Host "A recent restore point already exists, no new restore point was created." -ForegroundColor Yellow
}
@@ -777,11 +794,7 @@ function DisplayCustomModeOptions {
PrintHeader 'Custom Mode'
if ($( Read-Host -Prompt "Do you wish to create a system restore point? (y/n)" ) -eq 'y') {
AddParameter 'CreateRestorePoint' 'Create a system restore point'
}
Write-Output ""
AddParameter 'CreateRestorePoint' 'Create a system restore point'
# Show options for removing apps, only continue on valid input
Do {