SC's Dependency Problems

3 subcommands give you greater SC control

Mark Minasi

December 25, 2006

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

Last month, in “Taking 3 Swings at SC” (InstantDocID 93849), I showed you how to use Windows Server2003's SC (sc.exe) command to create a new service based on a fictional service application (i.e., C:wcwcmail.exe) that grabs pictures from a Web cam every few minutes.I walked you through the process of specifying a serviceaccount for the service, setting it to autostart, suppressingerror messages, and giving it a display name of “Web camimage mailer.” As you'll recall, the command we ended upwith was

sc create webimagemailer binpath= C:wcwcmail.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. Inservices terms, that would mean that Webimagemailer hasstisvc as a dependency. To instruct Webimagemailer towait until stisvc starts before starting itself, you would addthe depend= stisvc parameter. (Don't forget: SC requires aspace 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 aforward slash. For example, to create the Webimagemailerservice and specify that the stisvc and webclient servicesneed to be running before it can start, you'd type

sc create webimagemailer binpath= C:wcwcmail.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 usethree SC subcommands—enumdepends, qc, and config—to query SC about them. To determine which servicesdepend on a given service, you can type

sc enumdepend 

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 computerbrowser 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 aboutthe service, one of which is DEPENDENCIES. (SC tendsto shout.) If you run that command, you'll find that Serverdoesn't depend on any services. To see a service that hasmore than one dependency, try the command on theNetlogon service. You'll see that Netlogon requires boththe Server and Workstation services running before it canstart.

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

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

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

sc query type= all group= “primary disk”

Case doesn't seem to matter in group names. You can adda service to a given group, or create a new service group, byadding the group= groupname command to the SC Createcommand or by using SC Config to modify a service's groupmembership. For example, to add Webimagemailer to anew 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 morethan one service group.

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

sc config webimagemailer depends= +webstartup 

Now you've seen how to use dependencies and groups tomore specifically control a service's load order. You canunderstand why I was pleased to discover SC a few yearsago.

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