From b82ba886e62c616e102d8e84b2c2d07a7914af5d Mon Sep 17 00:00:00 2001 From: Padsala Tushal <57517785+padsalatushal@users.noreply.github.com> Date: Wed, 31 May 2023 08:49:36 +0530 Subject: [PATCH] add undoscript feature + implement it on every tweaks (#776) * add undoscript feature + implement it on right click menu - add undoscript feature - add undo for right click menu to go back to windows 11 default right click menu by implementing undoscript feature * undoscript for WPFMiscTweaksDisplay * undoscript for WPFEssTweaksRemoveEdge * undoscript for WPFEssTweaksRemoveCortana * undoscript for WPFEssTweaksStorage * Update Invoke-WinUtilTweaks.ps1 thanks to @DeveloperDurp * compile --- config/tweaks.json | 20 +++++++++ functions/private/Invoke-WinUtilTweaks.ps1 | 29 ++++++------ winutil.ps1 | 51 ++++++++++++++++------ 3 files changed, 73 insertions(+), 27 deletions(-) diff --git a/config/tweaks.json b/config/tweaks.json index 6d53c57c..58defab3 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -1922,6 +1922,9 @@ ], "InvokeScript": [ "Set-ItemProperty -Path \"HKCU:\\Control Panel\\Desktop\" -Name \"UserPreferencesMask\" -Type Binary -Value ([byte[]](144,18,3,128,16,0,0,0))" + ], + "UndoScript": [ + "Remove-ItemProperty -Path \"HKCU:\\Control Panel\\Desktop\" -Name \"UserPreferencesMask\"" ] }, "WPFEssTweaksDeBloat": { @@ -2055,6 +2058,10 @@ "WPFEssTweaksStorage": { "InvokeScript": [ "Remove-Item -Path \"HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\StorageSense\\Parameters\\StoragePolicy\" -Recurse -ErrorAction SilentlyContinue" + ], + "UndoScript": [ + "New-Item -Path \"HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\StorageSense\\Parameters\\StoragePolicy\" | Out-Null + " ] }, "WPFMiscTweaksLapNum": { @@ -2136,6 +2143,9 @@ } } " + ], + "UndoScript": [ + "winget install Microsoft.Edge" ] }, "WPFMiscTweaksDisableNotifications": { @@ -2159,6 +2169,12 @@ "WPFMiscTweaksRightClickMenu": { "InvokeScript": [ "New-Item -Path \"HKCU:\\Software\\Classes\\CLSID\\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\" -Name \"InprocServer32\" -force -value \"\" " + ], + "UndoScript": [ + " + Remove-Item -Path \"HKCU:\\Software\\Classes\\CLSID\\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\" -Recurse -Confirm:$false -Force + Write-Host Restart Needed for change + " ] }, "WPFEssTweaksDiskCleanup": { @@ -2258,6 +2274,10 @@ "WPFEssTweaksRemoveCortana": { "InvokeScript": [ "Get-AppxPackage -allusers Microsoft.549981C3F5F10 | Remove-AppxPackage" + ], + "UndoScript": [ + "Get-AppxPackage -allusers | where Name -like \"Microsoft.549981C3F5F10\" | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register \"$($_.InstallLocation)\\AppXManifest.xml\"} + " ] }, "WPFEssTweaksDVR": { diff --git a/functions/private/Invoke-WinUtilTweaks.ps1 b/functions/private/Invoke-WinUtilTweaks.ps1 index 61f10e10..a345b0a1 100644 --- a/functions/private/Invoke-WinUtilTweaks.ps1 +++ b/functions/private/Invoke-WinUtilTweaks.ps1 @@ -15,19 +15,16 @@ function Invoke-WinUtilTweaks { Registry = "OriginalValue" ScheduledTask = "OriginalState" Service = "OriginalType" + ScriptType = "UndoScript" } + } Else{ $Values = @{ Registry = "Value" ScheduledTask = "State" Service = "StartupType" - } - } - - if($sync.configs.tweaks.$CheckBox.registry){ - $sync.configs.tweaks.$CheckBox.registry | ForEach-Object { - Set-WinUtilRegistry -Name $psitem.Name -Path $psitem.Path -Type $psitem.Type -Value $psitem.$($values.registry) + ScriptType = "InvokeScript" } } if($sync.configs.tweaks.$CheckBox.ScheduledTask){ @@ -40,6 +37,17 @@ function Invoke-WinUtilTweaks { Set-WinUtilService -Name $psitem.Name -StartupType $psitem.$($values.Service) } } + if($sync.configs.tweaks.$CheckBox.registry){ + $sync.configs.tweaks.$CheckBox.registry | ForEach-Object { + Set-WinUtilRegistry -Name $psitem.Name -Path $psitem.Path -Type $psitem.Type -Value $psitem.$($values.registry) + } + } + if($sync.configs.tweaks.$CheckBox.$($values.ScriptType)){ + $sync.configs.tweaks.$CheckBox.$($values.ScriptType) | ForEach-Object { + $Scriptblock = [scriptblock]::Create($psitem) + Invoke-WinUtilScript -ScriptBlock $scriptblock -Name $CheckBox + } + } if(!$undo){ if($sync.configs.tweaks.$CheckBox.appx){ @@ -47,11 +55,6 @@ function Invoke-WinUtilTweaks { Remove-WinUtilAPPX -Name $psitem } } - if($sync.configs.tweaks.$CheckBox.InvokeScript){ - $sync.configs.tweaks.$CheckBox.InvokeScript | ForEach-Object { - $Scriptblock = [scriptblock]::Create($psitem) - Invoke-WinUtilScript -ScriptBlock $scriptblock -Name $CheckBox - } - } + } -} +} \ No newline at end of file diff --git a/winutil.ps1 b/winutil.ps1 index f311a74a..294f279e 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -10,7 +10,7 @@ Author : Chris Titus @christitustech Runspace Author: @DeveloperDurp GitHub : https://github.com/ChrisTitusTech - Version : 23.05.21 + Version : 23.05.27 #> Start-Transcript $ENV:TEMP\Winutil.log -Append @@ -21,7 +21,7 @@ Add-Type -AssemblyName System.Windows.Forms # variable to sync between runspaces $sync = [Hashtable]::Synchronized(@{}) $sync.PSScriptRoot = $PSScriptRoot -$sync.version = "23.05.21" +$sync.version = "23.05.27" $sync.configs = @{} $sync.ProcessRunning = $false Function Get-WinUtilCheckBoxes { @@ -546,19 +546,16 @@ function Invoke-WinUtilTweaks { Registry = "OriginalValue" ScheduledTask = "OriginalState" Service = "OriginalType" + ScriptType = "UndoScript" } + } Else{ $Values = @{ Registry = "Value" ScheduledTask = "State" Service = "StartupType" - } - } - - if($sync.configs.tweaks.$CheckBox.registry){ - $sync.configs.tweaks.$CheckBox.registry | ForEach-Object { - Set-WinUtilRegistry -Name $psitem.Name -Path $psitem.Path -Type $psitem.Type -Value $psitem.$($values.registry) + ScriptType = "InvokeScript" } } if($sync.configs.tweaks.$CheckBox.ScheduledTask){ @@ -571,6 +568,17 @@ function Invoke-WinUtilTweaks { Set-WinUtilService -Name $psitem.Name -StartupType $psitem.$($values.Service) } } + if($sync.configs.tweaks.$CheckBox.registry){ + $sync.configs.tweaks.$CheckBox.registry | ForEach-Object { + Set-WinUtilRegistry -Name $psitem.Name -Path $psitem.Path -Type $psitem.Type -Value $psitem.$($values.registry) + } + } + if($sync.configs.tweaks.$CheckBox.$($values.ScriptType)){ + $sync.configs.tweaks.$CheckBox.$($values.ScriptType) | ForEach-Object { + $Scriptblock = [scriptblock]::Create($psitem) + Invoke-WinUtilScript -ScriptBlock $scriptblock -Name $CheckBox + } + } if(!$undo){ if($sync.configs.tweaks.$CheckBox.appx){ @@ -578,12 +586,7 @@ function Invoke-WinUtilTweaks { Remove-WinUtilAPPX -Name $psitem } } - if($sync.configs.tweaks.$CheckBox.InvokeScript){ - $sync.configs.tweaks.$CheckBox.InvokeScript | ForEach-Object { - $Scriptblock = [scriptblock]::Create($psitem) - Invoke-WinUtilScript -ScriptBlock $scriptblock -Name $CheckBox - } - } + } } function Remove-WinUtilAPPX { @@ -4991,6 +4994,9 @@ $sync.configs.tweaks = '{ ], "InvokeScript": [ "Set-ItemProperty -Path \"HKCU:\\Control Panel\\Desktop\" -Name \"UserPreferencesMask\" -Type Binary -Value ([byte[]](144,18,3,128,16,0,0,0))" + ], + "UndoScript": [ + "Remove-ItemProperty -Path \"HKCU:\\Control Panel\\Desktop\" -Name \"UserPreferencesMask\"" ] }, "WPFEssTweaksDeBloat": { @@ -5124,6 +5130,10 @@ $sync.configs.tweaks = '{ "WPFEssTweaksStorage": { "InvokeScript": [ "Remove-Item -Path \"HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\StorageSense\\Parameters\\StoragePolicy\" -Recurse -ErrorAction SilentlyContinue" + ], + "UndoScript": [ + "New-Item -Path \"HKCU:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\StorageSense\\Parameters\\StoragePolicy\" | Out-Null + " ] }, "WPFMiscTweaksLapNum": { @@ -5205,6 +5215,9 @@ $sync.configs.tweaks = '{ } } " + ], + "UndoScript": [ + "winget install Microsoft.Edge" ] }, "WPFMiscTweaksDisableNotifications": { @@ -5228,6 +5241,12 @@ $sync.configs.tweaks = '{ "WPFMiscTweaksRightClickMenu": { "InvokeScript": [ "New-Item -Path \"HKCU:\\Software\\Classes\\CLSID\\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\" -Name \"InprocServer32\" -force -value \"\" " + ], + "UndoScript": [ + " + Remove-Item -Path \"HKCU:\\Software\\Classes\\CLSID\\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}\" -Recurse -Confirm:$false -Force + Write-Host Restart Needed for change + " ] }, "WPFEssTweaksDiskCleanup": { @@ -5327,6 +5346,10 @@ $sync.configs.tweaks = '{ "WPFEssTweaksRemoveCortana": { "InvokeScript": [ "Get-AppxPackage -allusers Microsoft.549981C3F5F10 | Remove-AppxPackage" + ], + "UndoScript": [ + "Get-AppxPackage -allusers | where Name -like \"Microsoft.549981C3F5F10\" | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register \"$($_.InstallLocation)\\AppXManifest.xml\"} + " ] }, "WPFEssTweaksDVR": {