Changing Services with the Command Line
March 30, 2014 Leave a comment
Changing services, whether changing the startup type or stopping/starting them, is something every user will have to do. While it’s easy to simply go through the Services MMC that can be time consuming, especially when a PC is being slow. The prefered method would be through the Command Line, either manually or through a pre-written batch file. So how do you do this? Check below for details.
The main commands we’re working with here are the
sc config
portion of the sc command and
net start/stop/restart
command. Both commands are capable of doing much more but we will only be concentrating on these specific functions today. I use GoodSync Synchronizer at home to sync directories and drives. One annoying this this program does on install is start a service for GoodSync Server. It’s a great function but not something I use on my desktop or actively on my servers right now. The problem is that every update re-enables it. Making changes to the service via a simply batch script is much easier than doing it through the MMC console. Below is batch script I use to accomplish the task.
@echo off net stop GsServer sc config GsServer start= disabled
This batch script does the following things: 1) stop the Goodsync Server if it’s running and 2) Change the services startup from its default setting of Automatic to Disabled. If you wanted to dig even further into the command you could make even more changes to the service. First we’ll take a look at the
net start/stop/restart
command. The net command can alter a variety of settings within windows. In this case we’re telling it to start, stop or restart a object which is the service. We can do that in one of tw0 ways: Either the full service name or by the display name. For example, the wireless networking service in Windows is called WLAN AutoConfig. There’s two ways we can refer to it in our script. Either the display name which is WLAN AutoConfig in quotations or the service name which would be Wlansvc. The command we would use would be either
net [start/stop/restart] "WLAN AutoConfig"
or
net [start/stop/restart] WLansvc
The next command we’ll look at is
sc config
This command is a little more complicated than the net command with its variety of options. The portion of the command we’re using specifically is the start option. The start option carries the following variables:
start= {boot | system | auto | demand | disabled | delayed-auto}
For most people, the only ones you’ll use are auto, demand or disabled. The demand options is essentially equivalent to the Manual option you would see in the MMC. Following the example of the wireless service we covered above we will look into how to change it with
sc config
To change the service (in this example, disabling it) we would use the command as such:
sc config Wlansvc start= disabled
or
sc config "WLAN AutoConfig" start= disabled
Since most people will disable the WLAN service on desktops and servers the batch script one would use to do so would be:
net stop Wlansvc | net stop "WLAN AutoConfig" sc config Wlansvc start= disabled | sc config "WLAN AutoConfig" start= disabled
A simple and easy way to change one or more services at once in one script rather then individually in the Windows MMC.
Extras:
*You can also pause and continue a service with the net command by using
net pause
or
net continue
respectively.