change service startup type

Glenn Maxwell 12,871 Reputation points
2020-12-07T18:34:01.65+00:00

Hi All

i have windows servers and i have the below service on those servers whose startup type is automatic, how can i change the startup type to Automatic Delayed Start using configuration manager or is it possible to do with any PowerShell script. Please guide me on this

Path to Executable:
"C:\Program Files\Software\Folder1\app.exe" service

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Gary Blok 1,756 Reputation points
    2020-12-08T06:35:05.283+00:00

    The "AutomaticDelayedStart" value is only available with PowerShell 6 and above.
    You'd need to leverage the registry value for now

    I'd suggest using the "Run Scripts" Feature as Youseff said, and using a script like this:

    [CmdletBinding()]
    Param (
    [Parameter(Mandatory=$true,Position=1,HelpMessage="Service Name")]
    [ValidateNotNullOrEmpty()]
    $ServiceName
    )

    if (Test-Path -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$ServiceName")
    {
    Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$ServiceName" -Name 'Start' -Value '1' -Force
    write-output "Value for $($ServiceName): $(Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$ServiceName" -Name 'Start')"
    }
    else
    {
    Write-Output "NO Service $ServiceName On this machine"
    }

    46050-image.png

    0 comments No comments

6 additional answers

Sort by: Most helpful
  1. Glenn Maxwell 12,871 Reputation points
    2020-12-08T21:31:19.85+00:00

    i have already tried by giving quotes but it did not work.


  2. Karl 1 Reputation point
    2021-05-18T10:10:33.253+00:00

    Something like this:

    Use this command to see the service details:

    Get-Service | Format-Table Status, Name, DisplayName -Autosize
    

    Take the Name of your service shown from this list and put it in the $ServiceName variable below, eg: $ServiceName = "Fred"

    For me, Windows Server 2019, PowerShell 5.1, Value 2 was Automatic (Delayed Start)

    Run the script with the Services panel open, then refresh the panel ( F5 ) - you should see the effect of your script
    Don't forget to run the Powershell environment using Run as administrator -- this is very important!

    $ServiceName = "<The name of your service>"
    
    if (Test-Path -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$ServiceName") {
        Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$ServiceName" -Name 'Start' -Value '2' -Force
    
        Write-Output "Value for $($ServiceName): $(Get-ItemPropertyValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$ServiceName" -Name 'Start')"
    }
    else {
        Write-Output "NO Service  $ServiceName  was found on this machine"
    }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.