JSI Tip 9045. How can I generate a CSV (Comma Separated Value) file of services and the account they run under?

Using REG.EXE, built into Windows XP, Windows Server 2003, and later, or installed from the Windows 2000 Support Tools, I have scripted SvcAcct.bat to generate a CSV file of services and the context that they run in.

The syntax for using SvcAcct.bat is:

SvcAcct CSVFileName

Where CSVFileName is the name of the CSV file that will be created.

SvcAcct.bat contains:

@echo off
if \{%1\}==\{\} @echo SvcAcct CSVFileName&goto :EOF
set file=%1
if exist %file% del /q %file%
set key="HKLM\System\currentcontrolset\services"
set keyf=HKEY_LOCAL_MACHINE\System\currentcontrolset\services
call :quiet>nul 2>&1
goto :EOF
for /f "Tokens=*" %%a in ('reg query %key% /S^|FINDSTR /I /L /C:"%keyf%"') do (
 set keys=%%a
 call set keyw=!keys:%keyf%=!
 set keyw=!keyw:~1!
 set keys=!keys:HKEY_LOCAL_MACHINE=HKLM!
 for /f "Tokens=1* Delims=\" %%x in ('@echo !keyw!') do (
  if "%%y" EQU "" for /f "Tokens=1,2*" %%i in ('reg query "!keys!" /V ObjectName^|FIND /I "ObjectName"^|FIND "REG_SZ"') do (
  @echo "!keys:~39!","%%k">>%file%

Hide 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.