JSI Tip 9695. How can I generate a CSV file containing the key and display name of running services?


Using REG.EXE, built into Windows XP, Windows Server 2003, and later, or installed on Windows 2000 from the Support Tools folder of of the Windows 2000 CD-ROM, I have scripted RunSvc.bat to generate a CSV (Comma Separated Value) file containing the Key and display name of running services. The output is written to RunSvc.csv in the current directory.

The syntax for using RunSvc.bat is:

RunSvc

RunSvc.bat contains:

@echo off
setlocal
if exist RunSvc.csv del /q RunSvc.csv
set work="%TEMP%\RunSvc_%RANDOM%.TMP"
set OK="HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\"
set qry=REG QUERY HKLM\System\CurrentControlSet\Services
if exist %work% del /q %work%
for /f "Skip=1 Tokens=*" %%a in ('net start^|find /v "The command completed successfully."') do (
 @echo %%a>>%work%
)
for /f "Tokens=*" %%a in ('%qry%^|find /i %OK%') do (
 call :getsvc "%%a">nul 2>&1
)
del /q %work%
endlocal
goto :EOF
:getsvc
for /f "Tokens=1,2*" %%b in ('REG Query %1 /V DisplayName^|Find "REG_SZ"^|Findstr /i /g:%work%') do (
  @echo %1,"%%d">>RunSvc.csv
)



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