ProblemYou 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 Note that the space after start= is required. 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, but can be started later manually. 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 in fact 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). See AlsoMSDN: Change Method of the Win32_Service Class |