mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-04-05 22:28:31 +00:00
* cleaned up typo, fixes, grammatical and other related fixes (#2) * typo in Lightshot app name * remove trailing comma in applications.json * consistent capitalization of Windows, WinGet - only user-facing text - includes update to devdocs-generator.ps1, so docs for tweaks modifying registry will have `Windows settings` rather than `windows settings` * various fixes for typos, style, punctuation and capitalization * capitalize 'AM' * Update README.md change formatting for GitHub UI interaction form code format (` `) to bold md Co-authored-by: Jay <65828559+Jay-o-Way@users.noreply.github.com> * typos and wording in docs --------- Co-authored-by: Jay <65828559+Jay-o-Way@users.noreply.github.com>
41 lines
1.2 KiB
PowerShell
41 lines
1.2 KiB
PowerShell
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
|
|
}
|
|
|
|
}
|