Unleashing SC on Service Configuration

One more look at this tool reveals its true power

Mark Minasi

January 29, 2007

3 Min Read
ITPro Today logo in a gray background | ITPro Today

Ready to finish our look at SC (sc.exe), the command-line tool that offers wide-reaching controlover services? In previous columns, I've demonstrated how SC lets you start and stop services, createnew ones, delete existing ones, and control dependenciesbetween services. But that's not all you can do with services. For example, I often find myself changing a service'sstartup status—whether it starts automatically or manually,whether it's disabled, and so on. You can control startupstatus, and much more, by using the SC Config command.

How It Works
The SC Config command largely mirrors the SC Create command, which I've covered before. Its overall syntax looks like

sc config     

Here's an example that will illustrate this command's usefulness: Ever since Windows Server 2003 Service Pack 1(SP1) and Windows XP SP2 disabled the Messenger service,I've gotten pretty regular email from people who say theyneed it. (Some folks really like the Net Send command.) Toconfigure the Messenger service to automatically start everytime you boot your computer, you could type

sc config messenger option= auto 

(Recall that SC has the syntactic quirk of requiring a spacebetween the equals sign and the option's value.) The otherpossible values are boot, system, demand (i.e., manual),and disabled.

By the way, Windows Vista systems have yet anotherpossible value—delayed-auto—that reflects Vista's newdelayed start option. The notion of delayed-start servicesreflects Microsoft's observation that many auto-start services need to start automatically but don't necessarily haveto start immediately. Microsoft wanted Vista to get startedup and ready to go as quickly as possible, and part of thereason why the XP and Windows 2000 desktop OSs bootslowly is because they're waiting for those auto-start services that always start immediately.

Other useful options for the SC Config command arepassword, error, depend, and perhaps obj. You're alreadyfamiliar with the obj and password options. A couple monthsago, I showed you how to use them for creating a new service:obj= lets you configure which account to run a service underwith SC Config just as the obj= parameter lets you specify the service account in SC Create. You probably won't changeservice accounts very often, but you might end up changingthose accounts' passwords, and for that task, you can use thepassword= option. If a service with a key name of myservicehas a service account whose password has changed to swordfish, you can inform Windows as follows:

sc config myservice password= swordfish 

You can use the error= option to control Windows'behavior when a service fails. Remember, while creating anew Windows service, you can tell Windows to respond toa service failure in one of four ways: ignore, which merelynotes the failure in the event log; normal, which acknowledges the failure with a message but lets operations continue; severe, which reboots the system with Last KnownGood and tries again; or critical, which reboots the system,retries the service, and—if it still fails to run—bluescreensthe system. I can tell Windows that if myservice doesn't run,Windows doesn't run (clearly a measure to use sparingly),as follows:

sc config myservice error= critical 

We're not quite done with SC Config—there's one moreoddity to look at. Over the course of the past three columns,I've shown you that whenever SC lets you specify more thanone option/value pair for a command, you separate thoseoption/value pairs with forward slashes. I demonstrated thetechnique last month with the depend= option, and youcan also observe it if you look up the syntax of Vista's SCcommand. By contrast, with SC Config, you specify morethan one option by merely separating them with spaces.(Granted, this behavior might be considered standard in thescripting world; it just seems odd in the context of SC's othersyntax.) For example, to combine those last two commandsinto one, I could type

sc config myservice password= swordfish error= critical

Consider the Possibilities
Need to control a service from the command line because youwant to use a batch file? Want to use a low-bandwidth textualinterface for remotely configuring a system? Perhaps you'rejust getting up to speed with the command line so that you cancontrol the upcoming command-line-only Server Core product. Whatever your scenario, you'll find SC a useful tool.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like