When managing Windows services, you might notice that some services show as Automatic (Delayed Start)
in services.msc
, but PowerShell's Get-Service
cmdlet simply reports them as Automatic
. This discrepancy occurs because the delayed start flag isn't exposed through the standard .NET ServiceController class that PowerShell uses.
The delayed start configuration is actually stored in the Windows Registry under:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<ServiceName>\DelayedAutostart
When this DWORD value is set to 1, the service uses delayed start. The standard Windows Service Control Manager API handles this setting, but PowerShell's Set-Service
cmdlet doesn't expose this functionality directly.
Here are three methods to configure delayed start services programmatically:
Method 1: Using Registry Modification
# Set delayed start for BITS service
$serviceName = "BITS"
Set-Service -Name $serviceName -StartupType Automatic
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Services\$serviceName"
Set-ItemProperty -Path $regPath -Name "DelayedAutostart" -Value 1 -Type DWORD
Method 2: Using sc.exe Utility
# Alternative using sc.exe
sc.exe config "BITS" start= delayed-auto
Method 3: Advanced PowerShell Function
function Set-ServiceDelayedStart {
param (
[string]$ServiceName,
[bool]$Delayed
)
if (-not (Get-Service $ServiceName -ErrorAction SilentlyContinue)) {
throw "Service '$ServiceName' not found"
}
try {
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Services\$ServiceName"
if ($Delayed) {
Set-Service -Name $ServiceName -StartupType Automatic
Set-ItemProperty -Path $regPath -Name "DelayedAutostart" -Value 1 -Type DWORD
}
else {
Set-Service -Name $ServiceName -StartupType Automatic
Remove-ItemProperty -Path $regPath -Name "DelayedAutostart" -ErrorAction SilentlyContinue
}
return $true
}
catch {
Write-Error $_.Exception.Message
return $false
}
}
# Usage example:
Set-ServiceDelayedStart -ServiceName "BITS" -Delayed $true
To confirm your changes took effect, either:
- Check services.msc GUI
- Run:
sc.exe qc "BITS" | find "START_TYPE"
- Inspect the registry value directly
In domain environments, you might prefer deploying these settings through Group Policy Preferences (GPP) or PowerShell DSC. Here's a DSC example:
Configuration ServiceConfig {
Node localhost {
Registry DelayedStartExample {
Key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BITS"
ValueName = "DelayedAutostart"
ValueData = 1
ValueType = "Dword"
Ensure = "Present"
}
}
}
ServiceConfig -OutputPath "C:\DSCConfigs"
Start-DscConfiguration -Path "C:\DSCConfigs" -Wait -Verbose
When managing Windows services through PowerShell, you'll notice that while services.msc
GUI allows setting "Automatic (Delayed Start)", this option isn't directly available through the standard Set-Service
cmdlet. The StartType
property only shows basic values like Automatic, Manual, or Disabled.
The delayed start configuration is actually stored in the Windows Registry under the service's configuration. Here's how you can modify it programmatically:
# First check if service exists
if (Get-Service "YourServiceName" -ErrorAction SilentlyContinue) {
# Set standard start type first
Set-Service -Name "YourServiceName" -StartupType Automatic
# Then modify the delayed start flag in registry
$service = Get-WmiObject -Class Win32_Service -Filter "Name='YourServiceName'"
$service.Change($null, $null, $null, $null, $null, $null, $null, $null, $null, $null, $null)
# Now set the DelayedAutoStart value
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Services\YourServiceName"
Set-ItemProperty -Path $regPath -Name "DelayedAutoStart" -Value 1 -Type DWord
}
For those who prefer command-line tools, the sc.exe
utility can achieve this:
# Set standard automatic start
sc config "YourServiceName" start= auto
# Set delayed start flag
sc failure "YourServiceName" actions= restart/60000/restart/60000/restart/60000 reset= 86400
After making changes, verify the configuration with:
Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\YourServiceName" |
Select-Object DelayedAutoStart
A value of 1 indicates delayed start is enabled, while 0 means it's disabled.
- Requires elevated PowerShell session (Run as Administrator)
- Some system services may not support delayed start
- Changes take effect after service restart
- Consider using
Restart-Service
after configuration changes
Here's how to batch configure several services for delayed start:
$services = @("wuauserv", "BITS", "Spooler")
foreach ($service in $services) {
try {
Set-Service -Name $service -StartupType Automatic
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\$service" -Name "DelayedAutoStart" -Value 1
Write-Output "Configured $service for delayed start"
}
catch {
Write-Warning "Failed to configure $service: $_"
}
}