mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-10-09 13:11:19 +11:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user