Recipe 7.4. Setting the Service Startup TypeProblemYou want to configure the startup type (automatic, manual, or disabled) for a service. SolutionUsing a graphical user interface
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 DiscussionThe 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 automatic service is dependent upon it, but it can be started later by someone with sufficient privileges. The Disabled startup type means that the service is not started at system boot up and cannot be manually started. You have to change the startup type to either Manual or Automatic before you can start a service that is set to Disabled. You may have noticed that there are two other startup options you can configure with the sc utility. These additional startup options are available with the scripting solution as well. They are, however, not applicable to system services. They are used for starting device drivers and can only be configured for drivers. The Boot startup type indicates that the driver is started by the operating system loader. The System startup type means that the driver will be started by the IoInitSystem method (if you are a driver programmer you know what this is, if not, don't worry about it). See AlsoMSDN: Change Method of the Win32_Service Class |