One of the benefits of having proper Windows service based applications – versus running “service” applications in an interactive command prompt – is that you get more controlled operations beyond “start” and “kill”. You also get the benefit of having nice tools to manage Windows services remotely. We’ll cover a few of the most common remote service management tools here:
- Services MMC: services.msc
- Service Control command line: sc
- PsTools command line: psservice
Services MMC: services.msc
This is the MMC snap-in for managing Windows services both locally and remotely by using the “Connect to Another Computer” option. This is the typical way administrators view and manage Windows services on a computer. You can open this snap-in by going to the Control Panel’s Administrative Tools and selecting Services from there or running the services.msc command.
It’s a fairly intuitive user interface: there’s a list of all Windows Services registered on the computer, there are clickable headers for sorting, and there are service control options in the toolbar and in the context menu.
From here you can start, stop, restart, or pause (if the application supports pausing) any Windows service on the machine you are viewing. You can also change many of the services’ properties, such as credentials used to run the service, and service start types including:
- Automatic (Delayed): Introduced in Windows Vista. The service will automatically be started shortly after Windows has finished booting and after its initial busy operations.
- Automatic: The service will start automatically when Windows starts.
- Manual: The service will only be started when asked to by a user or an external command.
- Disabled: The service won’t be started at all and all start operations (in services.msc or external commands) are disabled and ignored.
You can also modify service recovery options here, i.e. what to do, if anything, if the service stops unexpectedly.
Note that when starting or stopping a process in services.msc, you don’t need to wait for the progress bar to finish. This can be convenient if you’re manually starting or stopping several services on the same machine. Simply click the Close button on the progress bar dialog box after it pops up, or press the Escape key on your keyboard, and move on to the next service.
However, if you are doing a restart operation, be careful – if you close the progress bar dialog while the service is performing the “Stop” part of the restart, then the “Start” part of the restart operation will never happen and the service will just remain stopped.
Service Control command line: sc
You can use the built-in sc command to manage Windows services, both locally and remotely, using the Windows command line.
Note that sc requires the “service name” of the service you want to control. The names you see in services.msc are actually the services’ “display names”. Sometimes the display name and the service name are identical, but many times they are not. To see the service name of a service, go to the service’s properties in services.msc:
Some sc examples include:
To remotely restart the World Wide Web Publishing Service service on the host SERVER-A:
To stop the local SNMP Service:
It’s also worth noting that the sc command returns immediately, meaning it does not wait for the service to actually complete its operation (start, stop, etc.). You have to query the service’s status using “sc query” or services.msc or some other way in order to know when the service has actually completed the requested operation.
Unfortunately the sc command can only use your current Windows credentials, which means that if you don’t have access to the machine you want to manage (either locally or remotely), then sc won’t be very useful.
For more details on the other various sc options, run the command: sc /?
PsTools command line: PsService
The PsService command is part of the PsTools suite. It works almost exactly like the sc command, except that it also allows you to specify a username (and password) on the command line.
This means you can manage services as another Windows user, without having to interactively login to a machine as that user. This can be especially helpful if you have to manage services using a well known service login, or manage services on a machine that is not part of your Windows domain.
The command line syntax for PsService is almost identical to sc. For more details on the various PsService options, download PsTools and run the command: psservice /?