Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable/Disable Windows service using batch file

Is there any way to enable and disable a windows service using batch files. I am talking of changing the startup type of the services i.e. enabling and disabling and not starting and stopping using Net Start and Net Stop commands.

like image 839
Gautam Avatar asked Nov 01 '12 05:11

Gautam


People also ask

How do I stop a Windows service from a batch file?

In order to stop the service via batch script: Open cmd as administrator. Run this command: NET STOP <SERVICE_NAME>


1 Answers

sc config <service_name> start= disabled

This command has a number of functions but one is to determine the status of a service at system startup. A service can be set to run automatically, manually or not at all. The commands are

sc config ServiceName start= flag

Here ServiceName is the name of the service and flag has one of the values auto, demand. or disabled . For example, to set a service to run manually the command is

sc config ServiceName start= demand

Note that there must be a space after the equals sign. The correct value for the parameter ServiceName may not always be obvious and the next command can be used to find it for all services.

like image 184
Gautam Avatar answered Sep 18 '22 16:09

Gautam