Skip to content

Commit

Permalink
Make restore points optional, enabled by default (#1380)
Browse files Browse the repository at this point in the history
* Make restore points optional, enabled by default

* Tweaks order fix if restorepoint is checked
  • Loading branch information
munkk01 authored Jan 12, 2024
1 parent a86d722 commit 72e7792
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 86 deletions.
37 changes: 37 additions & 0 deletions config/tweaks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,43 @@
"
]
},
"WPFEssTweaksRestorePoint": {
"InvokeScript": [
"
# Check if the user has administrative privileges
if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host \"Please run this script as an administrator.\"
return
}

# Check if System Restore is enabled for the main drive
try {
# Try getting restore points to check if System Restore is enabled
Enable-ComputerRestore -Drive \"$env:SystemDrive\"
} catch {
Write-Host \"An error occurred while enabling System Restore: $_\"
}

# Check if the SystemRestorePointCreationFrequency value exists
$exists = Get-ItemProperty -path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SystemRestore\" -Name \"SystemRestorePointCreationFrequency\" -ErrorAction SilentlyContinue
if($null -eq $exists){
write-host 'Changing system to allow multiple restore points per day'
Set-ItemProperty -Path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SystemRestore\" -Name \"SystemRestorePointCreationFrequency\" -Value \"0\" -Type DWord -Force -ErrorAction Stop | Out-Null
}

# Get all the restore points for the current day
$existingRestorePoints = Get-ComputerRestorePoint | Where-Object { $_.CreationTime.Date -eq (Get-Date).Date }

# Check if there is already a restore point created today
if ($existingRestorePoints.Count -eq 0) {
$description = \"System Restore Point created by WinUtil\"

Checkpoint-Computer -Description $description -RestorePointType \"MODIFY_SETTINGS\"
Write-Host -ForegroundColor Green \"System Restore Point Created Successfully\"
}
"
]
},
"WPFEssTweaksOO": {
"InvokeScript": [
"curl.exe -s \"https://raw.githubusercontent.com/ChrisTitusTech/winutil/main/ooshutup10_winutil_settings.cfg\" -o $ENV:temp\\ooshutup10.cfg
Expand Down
40 changes: 0 additions & 40 deletions functions/private/Set-WinUtilRestorePoint.ps1

This file was deleted.

12 changes: 9 additions & 3 deletions functions/public/Invoke-WPFtweaksbutton.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ function Invoke-WPFtweaksbutton {

$sync.ProcessRunning = $true

Set-WinUtilRestorePoint
# Executes first if selected
if ("WPFEssTweaksRestorePoint" -in $Tweaks) {
Invoke-WinUtilTweaks "WPFEssTweaksRestorePoint"
}

Foreach ($tweak in $tweaks){
Invoke-WinUtilTweaks $tweak
# Execute other selected tweaks
foreach ($tweak in $tweaks) {
if ($tweak -ne "WPFEssTweaksRestorePoint") {
Invoke-WinUtilTweaks $tweak
}
}

$sync.ProcessRunning = $false
Expand Down
90 changes: 47 additions & 43 deletions winutil.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1786,46 +1786,6 @@ function Set-WinUtilRegistry {
Write-Warning $psitem.Exception.StackTrace
}
}
function Set-WinUtilRestorePoint {
<#
.SYNOPSIS
Creates a Restore Point
#>

# Check if the user has administrative privileges
if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "Please run this script as an administrator."
return
}

# Check if System Restore is enabled for the main drive
try {
# Try getting restore points to check if System Restore is enabled
Enable-ComputerRestore -Drive "$env:SystemDrive"
} catch {
Write-Host "An error occurred while enabling System Restore: $_"
}

# Check if the SystemRestorePointCreationFrequency value exists
$exists = Get-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -name "SystemRestorePointCreationFrequency" -ErrorAction SilentlyContinue
if($null -eq $exists){
write-host 'Changing system to allow multiple restore points per day'
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRestore" -Name "SystemRestorePointCreationFrequency" -Value "0" -Type DWord -Force -ErrorAction Stop | Out-Null
}

# Get all the restore points for the current day
$existingRestorePoints = Get-ComputerRestorePoint | Where-Object { $_.CreationTime.Date -eq (Get-Date).Date }

# Check if there is already a restore point created today
if ($existingRestorePoints.Count -eq 0) {
$description = "System Restore Point created by WinUtil"

Checkpoint-Computer -Description $description -RestorePointType "MODIFY_SETTINGS"
Write-Host -ForegroundColor Green "System Restore Point Created Successfully"
}
}
function Set-WinUtilScheduledTask {
<#
Expand Down Expand Up @@ -3316,10 +3276,16 @@ function Invoke-WPFtweaksbutton {

$sync.ProcessRunning = $true

Set-WinUtilRestorePoint
# Execute the WPFEssTweaksRestorePoint tweak first if it is selected
if ("WPFEssTweaksRestorePoint" -in $Tweaks) {
Invoke-WinUtilTweaks "WPFEssTweaksRestorePoint"
}

Foreach ($tweak in $tweaks){
Invoke-WinUtilTweaks $tweak
# Execute other selected tweaks
foreach ($tweak in $tweaks) {
if ($tweak -ne "WPFEssTweaksRestorePoint") {
Invoke-WinUtilTweaks $tweak
}
}

$sync.ProcessRunning = $false
Expand Down Expand Up @@ -4523,6 +4489,7 @@ $inputXML = '<Window x:Class="WinUtility.MainWindow"
<Border Grid.Row="1" Grid.Column="0">
<StackPanel Background="{MainBackgroundColor}" SnapsToDevicePixels="True">
<Label FontSize="16" Content="Essential Tweaks"/>
<CheckBox Name="WPFEssTweaksRestorePoint" Content="Create Restore Point" Margin="5,0" ToolTip="Creates a restore point at runtime in case a revert is needed from WinUtil modifications" IsChecked="True"/>
<CheckBox Name="WPFEssTweaksOO" Content="Run OO Shutup" Margin="5,0" ToolTip="Runs OO Shutup from https://www.oo-software.com/en/shutup10"/>
<CheckBox Name="WPFEssTweaksTele" Content="Disable Telemetry" Margin="5,0" ToolTip="Disables Microsoft Telemetry. Note: This will lock many Edge Browser settings. Microsoft spies heavily on you when using the Edge browser."/>
<CheckBox Name="WPFEssTweaksWifi" Content="Disable Wifi-Sense" Margin="5,0" ToolTip="Wifi Sense is a spying service that phones home all nearby scanned wifi networks and your current geo location."/>
Expand Down Expand Up @@ -9386,6 +9353,43 @@ $sync.configs.tweaks = '{
"
]
},
"WPFEssTweaksRestorePoint": {
"InvokeScript": [
"
# Check if the user has administrative privileges
if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host \"Please run this script as an administrator.\"
return
}
# Check if System Restore is enabled for the main drive
try {
# Try getting restore points to check if System Restore is enabled
Enable-ComputerRestore -Drive \"$env:SystemDrive\"
} catch {
Write-Host \"An error occurred while enabling System Restore: $_\"
}
# Check if the SystemRestorePointCreationFrequency value exists
$exists = Get-ItemProperty -path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SystemRestore\" -Name \"SystemRestorePointCreationFrequency\" -ErrorAction SilentlyContinue
if($null -eq $exists){
write-host ''Changing system to allow multiple restore points per day''
Set-ItemProperty -Path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SystemRestore\" -Name \"SystemRestorePointCreationFrequency\" -Value \"0\" -Type DWord -Force -ErrorAction Stop | Out-Null
}
# Get all the restore points for the current day
$existingRestorePoints = Get-ComputerRestorePoint | Where-Object { $_.CreationTime.Date -eq (Get-Date).Date }
# Check if there is already a restore point created today
if ($existingRestorePoints.Count -eq 0) {
$description = \"System Restore Point created by WinUtil\"
Checkpoint-Computer -Description $description -RestorePointType \"MODIFY_SETTINGS\"
Write-Host -ForegroundColor Green \"System Restore Point Created Successfully\"
}
"
]
},
"WPFEssTweaksOO": {
"InvokeScript": [
"curl.exe -s \"https://raw.githubusercontent.com/ChrisTitusTech/winutil/main/ooshutup10_winutil_settings.cfg\" -o $ENV:temp\\ooshutup10.cfg
Expand Down
1 change: 1 addition & 0 deletions xaml/inputXML.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@
<Border Grid.Row="1" Grid.Column="0">
<StackPanel Background="{MainBackgroundColor}" SnapsToDevicePixels="True">
<Label FontSize="16" Content="Essential Tweaks"/>
<CheckBox Name="WPFEssTweaksRestorePoint" Content="Create Restore Point" Margin="5,0" ToolTip="Creates a restore point at runtime in case a revert is needed from WinUtil modifications" IsChecked="True"/>
<CheckBox Name="WPFEssTweaksOO" Content="Run OO Shutup" Margin="5,0" ToolTip="Runs OO Shutup from https://www.oo-software.com/en/shutup10"/>
<CheckBox Name="WPFEssTweaksTele" Content="Disable Telemetry" Margin="5,0" ToolTip="Disables Microsoft Telemetry. Note: This will lock many Edge Browser settings. Microsoft spies heavily on you when using the Edge browser."/>
<CheckBox Name="WPFEssTweaksWifi" Content="Disable Wifi-Sense" Margin="5,0" ToolTip="Wifi Sense is a spying service that phones home all nearby scanned wifi networks and your current geo location."/>
Expand Down

0 comments on commit 72e7792

Please sign in to comment.