PowerShell / PSDscResources

MIT License
129 stars 53 forks source link

Service: Resource missing the option to set the startup type to 'Automatic (Delayed Start)' #4

Open johlju opened 8 years ago

johlju commented 8 years ago

I would like to see that we add the option to be able to set the startup type to 'Automatic (Delayed Start)' I propose that we add the value 'AutomaticDelayedStart' to the parameter StartupType.

To know if a service is set to delayed start the resource has to query the registry.

$service = Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Services\MSSQLSERVER'
$isDelayedAutostart = $service.DelayedAutostart -eq 1

And to set a resource to delayed start, we need to change that value in the registry to 1 which means 'Automatic (Delayed Start)'. And to remove delayed start we need to set the value to 0 which means that the startup type is set to 'Automatic'.

Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\MSSQLSERVER" `
    -Name "DelayedAutostart" -Value 1 -Type DWORD

Note: When changing this value in the registry it will not directly show in the service.msc (GUI). A restart seem to be necessary for the GUI to reflect the change. This has no bearing for us since we are only interested in the value in the registry and that the change actually are used when next restart occurs. And it does work in my tests, when changing the value to 1 for delayed start and restarting, the service will delay starting up.

torgro commented 7 years ago

Hi,

You could use the sc.exe tool to configure delayed startup on a service. Example for the DNS service:

"sc.exe Config DNS Start=Delayed-Auto"| iex

This way the GUI will reflect the change without a reboot.

Cheers