|
You can manage services through the command-line interface as well as the GUI; in some cases, the command line can be faster and easier.
There are two ways to do this. The first is with the net command. The commands net start servicename and net stop servicename start and stop a service on the local computer. If the service name has spaces in it, you must enclose the name in quotation marks ("), and you can specify either the service's Display Name (the name listed in the Services management display), or the shorter Service Key name.
These commands can be used to quickly and easily restart a service. For example, if you had recently accessed a network host by its DNS name and the host's IP address is now changed, or if the host was offline but is now online, your computer's DNS cache will still hang on to the out-of-date address or the failure result for several minutes. Restarting the DNS service will make it discard the old, incorrect information and refresh itself. You can do this with
net stop dns net start dns
A more powerful command-line service management utility is sc, which can manage services on other computers, change service settings, and list information about installed services.
However, to manage services with sc, you must know the service's "Service Key name", which is usually not the name displayed in the Services management window. You can use sc to get a list of all installed services and their Service Key names, or you can refer to Table 4.8 for the names of common Windows services; the key names are printed in boldface.
Here are some sample uses of the sc utility:
-
Print a list of all services installed on the local computer, including their Automatic/Manual/Disabled setting and their Service Key names (labeled SERVICE_NAME)
sc query
- Print a list of services installed on another computer named otherhost:
sc \\otherhost query
- Restart the IIS web server service on computer otherhost
sc \\otherhost w3svc stop sc \\otherhost w3svc start
To get a listing of sc's full command syntax, type these three lines in a command prompt window:
sc ? >x.txt y notepad x.txt
(You will not be prompted for the y line.) Open the Windows Help and Support Center and search for sc for details on each subcommand. |