I want to list all the current running services and output it to a .csv file. Does anyone know how to do this?
4 Answers
Might I be evil and suggest the Cygwin variant:
net start | sed -e '1,2d' -e ':a' -e N -e 's/\n /,/' -e ta > services.csv

- 9,127
- 1
- 32
- 47
A bit of good old shell script:
@echo off
setlocal
set SERVICES=
for /f "skip=1 tokens=*" %%S in ('%SystemRoot%\System32\net.exe start') do call :ADD_SERVICE %%S
echo Running services are : [%SERVICES%]
endlocal
goto END
:ADD_SERVICE
set SERVICE=%*
if "%SERVICE%" == "" goto END
if "%SERVICE%" == "The command completed successfully." goto END
set SERVICES=%SERVICES%%SERVICE%,
goto END
:END

- 5,232
- 3
- 17
- 20
-
Nice. I was trying to do that myself in a batch file, but failed miserably (and drowned my sorrows in sed, instead). – SmallClanger Nov 19 '10 at 09:56
most basic way would to do this would be;
net start > services.csv
Sysinternals has a lot of tools which will provider more granular detailed information from within your processes. Such as PsService , the same function piping the result to a file will export as needed "> filename.extension"

- 1,771
- 11
- 10
-
net start > services.csv worked but what I forgot to add is that every service has to be seperated by commas. Do you know how to do this? – Kraffs Nov 18 '10 at 15:48
-
give this a try through Powershell, Get-Process | Export-Csv c:\scripts\test.txt -force see http://technet.microsoft.com/en-us/library/ee176825.aspx for full documentation. – Nick O'Neil Nov 18 '10 at 16:01
-
-
sure you can download it free, a reboot might be necessary for the server to complete installation although another option is to utilize powershell on a workstation in the same domain to execute get-process including \\computername to query another machines resources. download link on the right side of this page http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx – Nick O'Neil Nov 18 '10 at 16:11
-
Powershell is available for Xp and 2003 but it is not installed by default. You should be able to download it from Microsoft Update as an optional update. – Matt McCarragher Nov 18 '10 at 16:11
I have a simpler command than the above examples. WMI is installed by default on Windows XP or Windows 2k3 and above, although to use the wmic.exe program, the machine may need to initialize before local operation. From a command prompt issue the command:
WMIC path Win32_Service where state='Running' get /format:csv
or, for a machine on the network:
WMIC /node:myserver Win32_Service where state='Running' get /format:csv
Redirect the output to a file of your choice.
Changing /format:csv to /format:list makes a human readable output. One of my servers gives this for its HP Insight service:
AcceptPause=TRUE
AcceptStop=TRUE
Caption=HP Insight Storage Agents
CheckPoint=0
CreationClassName=Win32_Service
Description=HP Insight Storage Agents
DesktopInteract=FALSE
DisplayName=HP Insight Storage Agents
ErrorControl=Normal
ExitCode=0
InstallDate=
Name=CqMgStor
PathName=C:\WINDOWS\system32\CpqMgmt\cqmgstor\cqmgstor.exe
ProcessId=1836
ServiceSpecificExitCode=0
ServiceType=Own Process
Started=TRUE
StartMode=Auto
StartName=LocalSystem
State=Running
Status=OK
SystemCreationClassName=Win32_ComputerSystem
SystemName=CRL500
TagId=0
WaitHint=0
Most likely, you have no interest in many of these attributes and values. Assuming you only want Name, Caption and Pathname for each running process, you might issue the following command specifying only these attributes:
WMIC /node:myserver path Win32_Service where state='Running' get name,caption,pathname /format:csv
Rob

- 2,806
- 1
- 19
- 22