SC Command Line Tool for Controlling, to Stop and Start Services on Windows
SC is one of the Windows XP Professional command-line tools.
SC or the executable file for this command line program sc.exe can be used to retrieve and set information about services running on the Windows computer.
SC command line tool communicates with the NT Service Controller and installed services on the computer.
It is possible to stop or start a service, and change its current status by using the SC.exe command line utility for XP users.
I used the SC.exe to stop or start a list of services by preparing a batch file which includes a series of SC.exe commands for stopping/starting the services I want.
You can also control the status of these services running on your computer by using the Services Microsoft Management Console (MMC) which is in the Administrative Tools menu.
You can set the Startup Type and Status properties in the Services Management Console.
But my requirement is when I concantrate on coding using the Microsoft Visual Studio IDE, and while building large solutions, I need all the sources that are consumed by not necessarily running services on my computer.
But when I'm not coding using the VS2008 IDE, I might use the MS SQL Server 2008 instance installed on my computer, so its service should be running by default, etc.
So I prepared a .bat file which includes all the SC STOP commands for services that I could stop, and run it by just clicking on the .bat batch file. So simple :)
SC Command Line Tool for stopping a service - hpqcxs08
In this section, I'll try to demonstrate how sc.exe can be used to stop a service with an example. I choose the "hpqcxs08" HP printer service as sample service. I'll use sc.exe command-line program to stop service with name "hpqcxs08".
Before running the command line tool SC.EXE you can find the short help guide about the sc.exe utility by just typing its "sc" and executing without parameters.
Here is the help guide for SC.exe command line utility for XP users.
After have a quick look up in the help documentation for SC.EXE command, we can run the sc.exe with STOP command passing the name of the service "hpqcxs08"
Of course on of the main parameters of SC.Exe program is the server name that we want to control the services that are running on.
The server or computer name should be in the form \\Server-Name. And after the STOP command, you should pass the service name.
The sample output for the above SC.exe STOP service command is like:
Preparing a Batch file (.bat) to Stop and Start a List of Services
In the first section of this tutorial, I said I use a batch file (.bat) to control a list of services, and this provides me a simplicity and gains me time.
Since I do not require to open the Services Management Console each time and find the services I want to stop among many others, and click STOP button, go to next service, etc.
Be sure a batch file is better.
Open an empty notepad document file.
Then write down the list of services with the SC.exe command parameters.
Be sure you use the service name as parameter.
And if you want to control a service that is running on an other computer that you have administrative priviledges then do not forget the server name or the computer name.
Save the text document as a batch file by changing its extension to .bat.
Just double-click on the file to execute it.
Here is my sample .bat batch file.