Hello,
I'm trying to get a list of running services but the output i get is only one service.
can someone help me?
Thanks
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Aug 13, 2011, 4:17 AM EDT
You need a reference to System.ServiceProcess.dll to run this:
s44 reputationPosted Aug 13, 2011, 4:56 AM EDT
s44 reputationPosted Aug 13, 2011, 5:09 AM EDT
can anyone see what is the problem?
VulpesRank #55 · 29.2K reputationPosted Aug 13, 2011, 5:24 AM EDT
If it's a multi-line textbox, then use:
txtAllProcess.Text += s.ServiceName + "\r\n";
I can't see any obvious way in either the Process class or the ServiceController class to associate one with the other.
However, you can associate a service with its ProcessId and then look up the Process object using Process.GetProcessById() if you use WMI to get the list of services. See the Win32_Service class (http://msdn.microsoft.com/en-us/library/aa394418(VS.85).aspx).
I'm about to go out so I haven't time to write the code just now but, if you haven't figured it out by then, I'll do something later today.
VulpesRank #55 · 29.2K reputationPosted Aug 13, 2011, 9:40 AM EDT
The process for many of the services will be shown as svchost (see http://en.wikipedia.org/wiki/Svchost)
You'll need to add a reference to System.Management.dll to run this code: