SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software Kodyaz Development Resources
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Windows, Windows Phone, SAP and ABAP, like SAP UI5, Screen Personas, etc.

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.

 SC is a command line program used for communicating with the
 NT Service Controller and services.
 sc <server> [command] [service name] <option1> <option2>...

The option <server> has the form "\\ServerName"
Further help on commands can be obtained by typing: "sc [command]"
query-----------Queries the status for a service, or
                        enumerates the status for types of services.
queryex---------Queries the extended status for a service, or
                        enumerates the status for types of services.
start-----------Starts a service.
pause-----------Sends a PAUSE control request to a service.
interrogate-----Sends an INTERROGATE control request to a service.
continue--------Sends a CONTINUE control request to a service.
stop------------Sends a STOP request to a service.
config----------Changes the configuration of a service (persistant).
description-----Changes the description of a service.
failure---------Changes the actions taken by a service upon failure.
qc--------------Queries the configuration information for a service.
qdescription----Queries the description for a service.
qfailure--------Queries the actions taken by a service upon failure.
delete----------Deletes a service (from the registry).
create----------Creates a service. (adds it to the registry).
control---------Sends a control to a service.
sdshow----------Displays a service's security descriptor.
sdset-----------Sets a service's security descriptor.
GetDisplayName--Gets the DisplayName for a service.
GetKeyName------Gets the ServiceKeyName for a service.
EnumDepend------Enumerates Service Dependencies.

The following commands don't require a service name:
sc <server> <command> <option>
boot------------(ok | bad) Indicates whether the last boot should
                        be saved as the last-known-good boot configuration
Lock------------Locks the Service Database
QueryLock-------Queries the LockStatus for the SCManager Database
sc start MyService

Would you like to see help for the QUERY and QUERYEX commands? [ y | n ]:

sc.exe command line tool

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.

sc \\servername STOP "hpqcxs08"

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:

SERVICE_NAME: hpqcxs08
WIN32_EXIT_CODE : 0 (0x0)

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.

sc \\servername STOP "hpqcxs08"
sc \\servername STOP "MSSQLFDLauncher$SQL2008RTM"
sc \\servername STOP "MSOLAP$SQL2008RTM"
sc \\servername STOP "ReportServer$SQL2008RTM"
sc \\servername STOP "MsDtsServer100"
sc \\servername STOP "SQLAgent$SQL2008RTM"
sc \\servername STOP "SQLBrowser"
sc \\servername STOP "wuauserv"
sc \\servername STOP "BITS"
sc \\servername STOP "helpsvc"
sc \\servername STOP "Irmon"
sc \\servername STOP "NIAIServ"
sc \\servername STOP "Virtual Server"

Windows Vista

Windows Vista Articles

Windows Vista Forums

Vista Blog

Microsoft Windows Vista Articles

Enable Windows Gadgets
no_more_irp_stack_locations Blue Screen Error Message
How to Activate Windows Vista Editions
What is Windows ReadyBoost and How to Configure ReadyBoost on Flash Disks
How to enable Previous Versions and How to restore files from Previous Versions
Windows Vista Parental Controls
What is Windows DreamScene - Where to download Windows DreamScene for Windows Vista
Windows Vista Tools - Sticky Notes
Windows Vista Tools - Snipping Tool
How to Install IIS 7 (Internet Information Services) for SQL Server 2005 Reporting Services
How to Install IIS 7.0 on Windows Vista RC1 Ultimate Edition (X64)
This file does not appear to be a CD image
Download Link for Microsoft Windows Vista Beta 2
How to Install Microsoft Windows Vista Beta 2
Microsoft Windows Vista Beta 2 (Build 5384) Installation Screenshots
Microsoft Windows Vista Beta 1 Installation

Copyright © 2004 - 2018 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems