JSI Tip 9969. How can I retrieve the services that are dependent upon a specified service?

Jerold Schulman

December 12, 2005

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


If first introduced the DependOnService Value Name in Configuring Service start up order.

Using REG.EXE, built into Windows XP and Windows Server 2003, or from the Windows 2000 Support Tools, I have scripted DependOnService.bat to retrieve all the service sub-keys that are dependent upon a specified service.

The syntax for using DependOnService.bat is:

FOR /F "TOKENS=*" %%s in ('DependOnService Service-Sub-key') do ( @echo %%s)

Where Service-Sub-key is the service sub-key, not the display name, of the service you wish to enumerate, like LanManServer or LanManWorkstation.

The out put is displayed on the console, one service per line. On my Windows XP workstation, using:

for /f "Tokens=*" %%s in ('DependOnService lanmanworkstation') do ( @echo %%s)

returns:

AlerterBrowserMessengerNetlogonRpcLocator

DependOnService contains:

@echo offif {%1}=={} @echo Syntax DependOnService Service-Sub-key&goto :EOFsetlocal ENABLEDELAYEDEXPANSIONset service=%1set service=%service:"=%set wrk="%TEMP%DependOnService_%RANDOM%.TMP"if exist %wrk% del /q %wrk%call :svc>nul 2>&1for /f "Tokens=*" %%s in ('type %wrk%') do ( set key=%%s set key=!key:~53! @echo !key!)if exist %wrk% del /q %wrk%endlocalgoto :EOF:svcset qry=REG QUERY HKLMSystemCurrentControlSetServicesset fnd=Find /i "HKEY_LOCAL_MACHINESystemCurrentControlSetServices"set fnds1=Find /i "DependOnService"set fnds2=Find /i "REG_MULTI_SZ"set fnds3=Find ""set fnds4=Find /i "%service%"for /f "Tokens=*" %%a in ('%qry%^|%fnd%') do ( for /f "Tokens= 1,2*" %%b in ('REG QUERY %%a /s^|%fnds1%^|%fnds2%^|%fnds3%^|%fnds4%') do (  @echo %%a>>%wrk% ))



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