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 


January 2007

SC's Dependency Problems

3 subcommands give you greater SC control
RSS
Subscribe to Windows IT Pro | See More Utilities Articles Here | Reprints
Or get the Monthly Online Pass—only $5.95 a month!

Last month, in “Taking 3 Swings at SC” (InstantDoc ID 93849), I showed you how to use Windows Server 2003's SC (sc.exe) command to create a new service based on a fictional service application (i.e., C:\wc\wcmail.exe) that grabs pictures from a Web cam every few minutes. I walked you through the process of specifying a service account for the service, setting it to autostart, suppressing error messages, and giving it a display name of “Web cam image mailer.” As you'll recall, the command we ended up with was

sc create webimagemailer binpath= C:\wc\wcmail.exe
  start= auto displayname= “Web cam image mailer”
  obj= .\webcamguy password= swordfish error= ignore 

This month, let's go a little deeper. Suppose Webimagemailer can't run until the Windows Image Acquisition (WIA) service—with the key name stisvc—is running. In services terms, that would mean that Webimagemailer has stisvc as a dependency. To instruct Webimagemailer to wait until stisvc starts before starting itself, you would add the depend= stisvc parameter. (Don't forget: SC requires a space between the equals sign and the parameter value.) To specify that a service depends on more than one service, you would list the services' key names, separated by a forward slash. For example, to create the Webimagemailer service and specify that the stisvc and webclient services need to be running before it can start, you'd type

sc create webimagemailer binpath= C:\wc\wcmail.exe
  start= auto displayname= “Web cam image mailer”
  obj= .\webcamguy password= swordfish error= ignore depend= stisvc/webclient 

While we're on the topic of dependencies, you can use three SC subcommands—enumdepends, qc, and config—to query SC about them. To determine which services depend on a given service, you can type

sc enumdepend <servicekeyname>

Thus, to see which services depend on the Server service— which has the key name lanmanserver, you'd type

sc enumdepend lanmanserver 

Running that command on my test Windows 2003 server, for example, reveals that Netlogon, Dfs, and the computer browser services depend on the Server service.

To accomplish the reverse and determine Server dependencies, you can use the qc subcommand, as in

sc qc lanmanserver

This command dumps nine lines of information about the service, one of which is DEPENDENCIES. (SC tends to shout.) If you run that command, you'll find that Server doesn't depend on any services. To see a service that has more than one dependency, try the command on the Netlogon service. You'll see that Netlogon requires both the Server and Workstation services running before it can start.

Sometimes, dependencies are more complex than merely one service needing another. For example, some services will start only if one of three other services has started. (All three needn't be running; any one of the three will do.) You can instruct Windows about such a dynamic by informing the system that a given service depends on a group of services. Windows has a number of these services, such as the SCSI CDROM Class, SCSI miniport, Parallel arbitrator, NetBIOSGroup, NDIS, and Primary Disk services, to name a few. You can see all the services and drivers in a group by typing

sc query type= service|driver|all group= <”groupname”>

For example, to see all the services and drivers in the Primary Disk service group, you'd type

sc query type= all group= “primary disk”

Case doesn't seem to matter in group names. You can add a service to a given group, or create a new service group, by adding the group= groupname command to the SC Create command or by using SC Config to modify a service's group membership. For example, to add Webimagemailer to a new group named “unimportant,” you'd type

sc config webimagemailer group= unimportant  

As far as I can see, you can't put a service or driver in more than one service group.

You can also tell Windows that Webimagemailer shouldn't load without a particular group. To specify the fictional Webstartup group, you'd use the depends= webstartup parameter. To signal to Windows that Webstartup is a group—not another service—you'd prefix its name with a plus sign. For example, to reconfigure Webimagemailer to depend on the Webstartup startup group, you'd type

sc config webimagemailer depends= +webstartup 

Now you've seen how to use dependencies and groups to more specifically control a service's load order. You can understand why I was pleased to discover SC a few years ago.

End of Article



Reader Comments
Great stuff!

How would I amend the above service creation statement to show that the webimagemailer service is dependent on the webclient service locally, but also on the stisvc service which resides on \\someServer @ IP 1.2.3.4?

vicGar April 10, 2008 (Article Rating: )


From Mark Minasi:

I don’t think you can do that – I believe that dependencies must be within the same server’s services. (Neat idea, though!) Thanks for reading.

Jason Bovberg May 21, 2008 (Article Rating: )


You must log on before posting a comment.

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




Top Viewed ArticlesView all articles
The Memory-Optimization Hoax

Don't believe the hype. At best, RAM optimizers have no effect. At worst, they seriously degrade performance. ...

How can I uninstall the Microsoft Java Virtual Machine (JVM) from Windows XP?

...

What service packs and fixes are available?

...


Windows OSs Whitepapers Replay for Exchange: Enterprise Protection and an Affordable Price

Are You Satisfied?

A Preliminary Look at Deployment Plans for Microsoft Windows Vista

Related Events Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Disaster Recovery and Backup

A Guide to Windows Certification and Public Keys

Related Windows OSs 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.


ADS BY GOOGLE SPONSORED LINKS FEATURED LINKS

Critical Challenges of ESI & Email Retention
Are you storing too much electronic information? Get expert legal advice and better understanding of what you are required to do as an IT professional.

Become a fan of Windows IT Pro on Facebook!
Join us on Facebook and be a fan of Windows IT Pro!

Sustainable Compliance: Are You Having a Resource Crisis?
Read this white paper to examine trends in compliance and security management and review approaches to reducing the cost and operational burden of compliance.

Rev Up Your IT Know-How with Our Recharged Magazine!
The improved Windows IT Pro provides trusted IT content with an enhanced new look and functionality! Get comprehensive coverage of industry topics, expert advice, and real-world solutions—PLUS access to over 10,000 articles online. Order today!

Get It All with Windows IT Pro VIP
Stock your IT toolbox with every solution ever printed in Windows IT Pro and SQL Server Magazine plus bonus Web-exclusive content on hot topics. Subscribe to receive the VIP CD and a subscription to your choice of Windows IT Pro or SQL Server Magazine!



Order Your Fundamentals CD Today!
Gain an introduction to Exchange, learn server security requirements, and understand how unified communications can play a role in your messaging strategies with this free Exchange CD.
Windows IT Pro Home Register About Us Affiliates / Licensing Media Kit Contact Us/Customer Service  
SQL Connected Home IT Library SuperSite FAQ Wininfo News
Europe Edition Office & SharePoint Pro Windows Dev Pro Windows Excavator 
 
 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