Manage OS Triggered Services effectively in Windows 7 using sc.exe


We all work with Windows applications which have interactive system services to handle.  Sometimes we tend to mend the registry keys to configure the service settings, which is never a Best Practice!!.

Sc.exe is a Service Management Utility which solves this purpose. It is a command line program which is primarily used for communicating with the Service Control Manager (SCM) and the services.  With this utility, you can do the below operations with ease.

  1. Query the status of a service
  2. Create a service using a command line
  3. Start, pause, continue and stop a service
  4. Interrogate control requests to a service
  5. Change the configuration of a service
  6. Change the actions taken by the service upon failure
  7. Query the service SID type of a service
  8. Queries the triggered parameters of a services (Triggered Services is a model implemented in Windows 7)
  9. Enumerates service dependencies
  10. You can also lock the SCM database

The general usage of this command would be.,

sc <server> [command] [service name] <option1> <option2>..

Developers and administrators should never edit the registry to configure service settings. Instead, they should use sc.exe, the services MMC snap-in, or the SCM client API.

Few Examples Usages:

By using a triggerinfo switch we can get the status of a trigger service “browser” and its status, along with the port configurations

triggerinfo

In this example, we just use the query switch which displays the type, state, exit code, checkpoint and the wait_hint for the “bits” service.
query

Windows also includes an MMC snap-in—services.msc—that provides basic SCM functionality through a graphical user interface.