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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Aug 13, 2011, 1:40 PM
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:
VulpesPosted Aug 13, 2011, 9:24 AM
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.
sPosted Aug 13, 2011, 9:09 AM
can anyone see what is the problem?
sPosted Aug 13, 2011, 8:56 AM
VulpesPosted Aug 13, 2011, 8:17 AM
You need a reference to System.ServiceProcess.dll to run this: