Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


February 2007

Unleashing SC on Service Configuration

One more look at this tool reveals its true power
RSS
Subscribe to Windows IT Pro | See More Resource Kit Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Ready to finish our look at SC (sc.exe), the command-line tool that offers wide-reaching control over services? In previous columns, I've demonstrated how SC lets you start and stop services, create new ones, delete existing ones, and control dependencies between services. But that's not all you can do with services. For example, I often find myself changing a service's startup status—whether it starts automatically or manually, whether it's disabled, and so on. You can control startup status, 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 <servicekeyname> <option= value>   
<option= value>

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 they need it. (Some folks really like the Net Send command.) To configure the Messenger service to automatically start every time you boot your computer, you could type

sc config messenger option= auto 

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

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

Other useful options for the SC Config command are password, error, depend, and perhaps obj. You're already familiar with the obj and password options. A couple months ago, I showed you how to use them for creating a new service: obj= lets you configure which account to run a service under with SC Config just as the obj= parameter lets you specify the service account in SC Create. You probably won't change service accounts very often, but you might end up changing those accounts' passwords, and for that task, you can use the password= option. If a service with a key name of myservice has 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 a new Windows service, you can tell Windows to respond to a service failure in one of four ways: ignore, which merely notes 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 Known Good and tries again; or critical, which reboots the system, retries the service, and—if it still fails to run—bluescreens the 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 more oddity to look at. Over the course of the past three columns, I've shown you that whenever SC lets you specify more than one option/value pair for a command, you separate those option/value pairs with forward slashes. I demonstrated the technique last month with the depend= option, and you can also observe it if you look up the syntax of Vista's SC command. By contrast, with SC Config, you specify more than one option by merely separating them with spaces. (Granted, this behavior might be considered standard in the scripting world; it just seems odd in the context of SC's other syntax.) For example, to combine those last two commands into one, I could type

sc config myservice password= swordfish error= critical

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

End of Article



Reader Comments

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Friday at PASS Europe 2006

Kevin talks about the closing day of the event and shares a funny Microsoft film. ...

PsExec

This freeware utility lets you execute processes on a remote system and redirect output to the local system. ...

Escape From Yesterworld

Kevin points you to the funniest SQL Server website ever! ...


Related Articles Castaway on Command-Prompt Island

Task Automation Whitepapers Essential Guide to E-discovery and Recovery for Microsoft Exchange

Continuous Data Protection and Recovery for Microsoft Exchange

Protecting (You and) Your Data with Exchange Server 2007

Related Events Check out our list of Free Email Newsletters!

Task Automation eBooks Spam Fighting and Email Security for the 21st Century

A Guide to Windows Certification and Public Keys

Keeping Your Business Safe from Attack: Patch Management

Related Task Automation Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing