diff --git a/config/tweaks.json b/config/tweaks.json index a61597c428..ead26d6216 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -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 diff --git a/functions/private/Set-WinUtilRestorePoint.ps1 b/functions/private/Set-WinUtilRestorePoint.ps1 deleted file mode 100644 index 79618a12e5..0000000000 --- a/functions/private/Set-WinUtilRestorePoint.ps1 +++ /dev/null @@ -1,40 +0,0 @@ -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" - } -} diff --git a/functions/public/Invoke-WPFtweaksbutton.ps1 b/functions/public/Invoke-WPFtweaksbutton.ps1 index a037653ea7..90d7b00d06 100644 --- a/functions/public/Invoke-WPFtweaksbutton.ps1 +++ b/functions/public/Invoke-WPFtweaksbutton.ps1 @@ -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 diff --git a/winutil.ps1 b/winutil.ps1 index eb80140619..38098aae15 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -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 { <# @@ -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 @@ -4523,6 +4489,7 @@ $inputXML = '