fix(tweaks): skip missing services instead of aborting the run (#5140)

Invoke-WinUtilTweaks caught a missing service with [System.ServiceProcess.ServiceNotFoundException], a type that does not exist in .NET. PowerShell could not resolve the catch type, so the missing-service case aborted the whole tweaks job rather than warning.

Catch on the error ID the way Set-WinUtilService already does: an absent service warns and logs, and any unrelated lookup failure is rethrown. The Tweaks guide documents the skip.
This commit is contained in:
Omar
2026-10-07 09:43:22 -05:00
committed by GitHub
parent 9c87c02fdb
commit 07ccd8e2e7
3 changed files with 73 additions and 3 deletions
+10 -3
View File
@@ -48,14 +48,21 @@ function Invoke-WinUtilTweaks {
# The check for !($undo) is required, without it the script will throw an error for accessing unavailable member, which's the 'OriginalService' Property
if ($KeepServiceStartup -AND !($undo)) {
$serviceName = $psitem.Name
try {
# Check if the service exists
$service = Get-Service -Name $psitem.Name -ErrorAction Stop
$service = Get-Service -Name $serviceName -ErrorAction Stop
if(!($service.StartType.ToString() -eq $psitem.$($values.OriginalService))) {
$changeservice = $false
}
} catch [System.ServiceProcess.ServiceNotFoundException] {
Write-Warning "Service $($psitem.Name) was not found."
} catch {
if ($_.FullyQualifiedErrorId -like "NoServiceFoundForGivenName,*") {
$changeservice = $false
Write-Warning "Service $serviceName was not found."
Write-WinUtilLog -Level "WARN" -Component "Service" -Message "Service $serviceName was not found."
} else {
throw
}
}
}