Skip navigation

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


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:
Alerter
Browser
Messenger
Netlogon
RpcLocator
DependOnService contains:
@echo off
if \{%1\}==\{\} @echo Syntax DependOnService Service-Sub-key&goto :EOF
setlocal ENABLEDELAYEDEXPANSION
set service=%1
set service=%service:"=%
set wrk="%TEMP%\DependOnService_%RANDOM%.TMP"
if exist %wrk% del /q %wrk%
call :svc>nul 2>&1
for /f "Tokens=*" %%s in ('type %wrk%') do (
 set key=%%s
 set key=!key:~53!
 @echo !key!
)
if exist %wrk% del /q %wrk%
endlocal
goto :EOF
:svc
set qry=REG QUERY HKLM\System\CurrentControlSet\Services
set fnd=Find /i "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\"
set fnds1=Find /i "DependOnService"
set fnds2=Find /i "REG_MULTI_SZ"
set fnds3=Find "\0\0"
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%
 )
)



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish