7.4. Setting the Service Startup Type

Problem

You want to configure the startup type (automatic, manual, or disabled) for a service.

Solution

Using a graphical user interface

  1. Open the Services snap-in.

  2. In the left pane, double-click on the service you want to configure.

  3. Choose the startup type under the General tab.

  4. Click OK.

Using a command-line interface:

> sc config <ServiceName> start= [boot | system | auto | demand | disabled]

The following command disables the Messenger service:

> sc config Messenger start= disabled

Using VBScript

' This code sets the startup type for a service.
' ------ SCRIPT CONFIGURATION ------
strSvcName     = "MyMonitor"
strStartupType = "Automatic"  ' can be "Automatic", "Manual", or "Disabled"
strComputer    = "."
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set objService = objWMI.Get("Win32_Service.Name='" & strSvcName & "'")
intRC = objService.Change(,,,,strStartupType)
' can alternatively use objService.ChangeStartup(strStartupType) method
if intRC > 0 then
   WScript.Echo "Error setting service startup type: " & intRC
else
   WScript.Echo "Successfully set service startup type"
end if

Discussion

The startup type of a service determines whether the service starts when the system boots and whether it can be started at all. The Automatic startup type causes the service to automatically start at system boot up. The Manual startup type means the service will not be started automatically at system boot up unless another ...

Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.