mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-12-17 09:45:22 +00:00
[Tweaks] Conditionally determine when to use sc and Set-Service (#3761)
* [Tweaks] Conditionally determine when to use sc and Set-Service * Clean up comments in Set-WinUtilService.ps1 Removed comments explaining the handling of auto delayed start for PWSH 5. --------- Co-authored-by: Chris Titus <contact@christitus.com>
This commit is contained in:
parent
becfba603d
commit
cfaf139a6a
@ -24,8 +24,12 @@ Function Set-WinUtilService {
|
|||||||
# Check if the service exists
|
# Check if the service exists
|
||||||
$service = Get-Service -Name $Name -ErrorAction Stop
|
$service = Get-Service -Name $Name -ErrorAction Stop
|
||||||
|
|
||||||
# Service exists, proceed with changing properties
|
# 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
|
$service | Set-Service -StartupType $StartupType -ErrorAction Stop
|
||||||
|
}
|
||||||
} catch [System.ServiceProcess.ServiceNotFoundException] {
|
} catch [System.ServiceProcess.ServiceNotFoundException] {
|
||||||
Write-Warning "Service $Name was not found"
|
Write-Warning "Service $Name was not found"
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user