diff --git a/config/tweaks.json b/config/tweaks.json index 43a8a7bddf..b91ce7ae98 100644 --- a/config/tweaks.json +++ b/config/tweaks.json @@ -140,12 +140,11 @@ "Description": "Disables Location Tracking.", "category": "Essential Tweaks", "panel": "1", - "service": [ - { - "Name": "lfsvc", - "StartupType": "Disable", - "OriginalType": "Manual" - } + "InvokeScript": [ + "Set-Service -Name lfsvc -StartupType Disabled" + ], + "UndoScript": [ + "Set-Service -Name lfsvc -StartupType Manual" ], "registry": [ { @@ -177,39 +176,27 @@ "Description": "Sets some services to Manual startup and adjusts the SvcHostSplitThresholdInKB registry value to better match system memory, which can significantly reduce the number of svchost.exe processes.", "category": "Essential Tweaks", "panel": "1", - "service": [ - { - "Name": "CscService", - "StartupType": "Disabled", - "OriginalType": "Manual" - }, - { - "Name": "DiagTrack", - "StartupType": "Disabled", - "OriginalType": "Automatic" - }, - { - "Name": "MapsBroker", - "StartupType": "Manual", - "OriginalType": "Automatic" - }, - { - "Name": "StorSvc", - "StartupType": "Manual", - "OriginalType": "Automatic" - }, - { - "Name": "SharedAccess", - "StartupType": "Disabled", - "OriginalType": "Automatic" - } - ], "InvokeScript": [ " + Set-Service -Name SharedAccess -StartupType Disabled + Set-Service -Name CscService -StartupType Disabled + Set-Service -Name DiagTrack -StartupType Disabled + Set-Service -Name MapsBroker -StartupType Manual + Set-Service -Name StorSvc -StartupType Manual + $Memory = (Get-CimInstance Win32_PhysicalMemory | Measure-Object Capacity -Sum).Sum / 1KB Set-ItemProperty -Path \"HKLM:\\SYSTEM\\CurrentControlSet\\Control\" -Name SvcHostSplitThresholdInKB -Value $Memory " ], + "UndoScript": [ + " + Set-Service -Name SharedAccess -StartupType Automatic + Set-Service -Name MapsBroker -StartupType Automatic + Set-Service -Name DiagTrack -StartupType Automatic + Set-Service -Name StorSvc -StartupType Automatic + Set-Service -Name CscService -StartupType Manual + " + ], "link": "https://winutil.christitus.com/dev/tweaks/essential-tweaks/services" }, "WPFTweaksBraveDebloat": { diff --git a/functions/private/Invoke-WinUtilCurrentSystem.ps1 b/functions/private/Invoke-WinUtilCurrentSystem.ps1 index 23fa7a1472..5c50fee512 100644 --- a/functions/private/Invoke-WinUtilCurrentSystem.ps1 +++ b/functions/private/Invoke-WinUtilCurrentSystem.ps1 @@ -50,12 +50,11 @@ Function Invoke-WinUtilCurrentSystem { $Config = $psitem.Name $entry = $sync.configs.tweaks.$Config $registryKeys = $entry.registry - $serviceKeys = $entry.service $appxKeys = $entry.appx $invokeScript = $entry.InvokeScript $entryType = $entry.Type - if ($registryKeys -or $serviceKeys) { + if ($registryKeys) { $Values = @() if ($entryType -eq "Toggle") { @@ -100,20 +99,6 @@ Function Invoke-WinUtilCurrentSystem { } } - Foreach ($tweaks in $serviceKeys) { - Foreach ($tweak in $tweaks) { - $Service = Get-Service -Name $tweak.Name - - if ($Service) { - $actualValue = $Service.StartType - $expectedValue = $tweak.StartupType - if ($expectedValue -ne $actualValue) { - $values += $False - } - } - } - } - if ($values -notcontains $false) { Write-Output $Config } diff --git a/functions/private/Set-WinUtilService.ps1 b/functions/private/Set-WinUtilService.ps1 deleted file mode 100644 index 3ef8bd0630..0000000000 --- a/functions/private/Set-WinUtilService.ps1 +++ /dev/null @@ -1,40 +0,0 @@ -Function Set-WinUtilService { - <# - - .SYNOPSIS - Changes the startup type of the given service - - .PARAMETER Name - The name of the service to modify - - .PARAMETER StartupType - The startup type to set the service to - - .EXAMPLE - Set-WinUtilService -Name "HomeGroupListener" -StartupType "Manual" - - #> - param ( - $Name, - $StartupType - ) - try { - Write-Host "Setting Service $Name to $StartupType" - - # Check if the service exists - $service = Get-Service -Name $Name -ErrorAction Stop - - # Service exists, proceed with changing properties -- while handling auto delayed start for PWSH 5 - if (($PSVersionTable.PSVersion.Major -lt 7) -and ($StartupType -eq "AutomaticDelayedStart")) { - sc.exe config $Name start=delayed-auto - } else { - $service | Set-Service -StartupType $StartupType -ErrorAction Stop - } - } catch [System.ServiceProcess.ServiceNotFoundException] { - Write-Warning "Service $Name was not found." - } catch { - Write-Warning "Unable to set $Name due to unhandled exception." - Write-Warning $_.Exception.Message - } - -}