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-07T21:38:10.34+00:00

    i am trying the below script. i have my servers in text file. i am getting the below error please correct me with the script

    $SL = "C:\list.txt"
    $SS = get-Content -Path $SL
    foreach ($Servers in $SS ) {
    Invoke-Command -ComputerName $Servers -ScriptBlock {
    sc.exe config MyServiceName start= delayed-auto
    }
    }

    [server01] Connecting to remote server server01 failed with the following error message : The client cannot connect
    to the destination specified in the request. Verify that the service on the destination is running and is accepting
    requests.

    • CategoryInfo : OpenError: (server01:String) [], PSRemotingTransportException
    • FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken

    Will the below script work for me

    Powershell
    $SL = "C:\list.txt"
    $SS = get-Content -Path $SL
    foreach ($Servers in $SS ) {
    Invoke-Command -ComputerName $Servers -ScriptBlock {
    Set-itemproperty -name Start -path "HKLM:\System\CurrentControlSet\Services\MyService" -value "1"
    }
    }

    0 comments No comments

  2. Youssef Saad 3,416 Reputation points
    2020-12-07T21:43:02.603+00:00

    Hi @Glenn Maxwell ,

    You can create a Powershell script on ConfigMgr with the following command and run it on the target device collection:

    • Set-Service -Name "Service name" -StartupType AutomaticDelayedStart

    Refer to the following guide:

    Regards,


    Youssef Saad | New blog: https://youssef-saad.blogspot.com/

    Please **remember to “Accept answer” ** for useful answers, thank you!

    0 comments No comments

  3. Glenn Maxwell 12,871 Reputation points
    2020-12-08T00:07:15.393+00:00

    Before trying from configMgr i have tried to execute the below command on one server from PowerShell I am getting the below error.

    Set-Service -Name MyService -StartupType AutomaticDelayedStart

    Set-Service : Cannot bind parameter 'StartupType'. Cannot convert value "AutomaticDelayedStart" to type
    "System.ServiceProcess.ServiceStartMode". Error: "Unable to match the identifier name AutomaticDelayedStart to a valid
    enumerator name. Specify one of the following enumerator names and try again: Boot, System, Automatic, Manual,
    Disabled"
    At line:1 char:48

    • Set-Service -Name MyService -StartupType AutomaticDelayedStart
    • ~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidArgument: (:) [Set-Service], ParameterBindingException
    • FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.SetServiceCommand

  4. Glenn Maxwell 12,871 Reputation points
    2020-12-08T10:34:47.35+00:00

    Below information is displayed from services. MSc
    ServiceName: MyAPP
    Display Name: MyAPP Service
    Path to executable: "C:\Program Files\Software\Folder1\app.exe" service

    From Registries

    Registry: HKLM:\SYSTEM\CurrentControlSet\Services\MyAPP
    DisplyName: MyAPP Service

    will the below script work for me

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

    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"
    }


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.