SIGN UP MEMBER LOGIN:    
ARTICLE

Get all Services on a System using C#

Posted by Mahesh Chand Articles | Windows Services in C# August 03, 2010
How to get all services installed on a machine using C#.
Reader Level:

ServiceController class defined in the System.ServiceProcess namespace is used to work with services. ServiceController.GetServices static method gets all services installed on a machine.

This code snippet demonstrates how to get all services installed on a machine and list them in a ListBox control.

Create a Windows Forms application, add a ListBox control onto the Form, add following code and call GetAllServices method on the Form's load event handler.


private
void GetAllServices()
{
foreach (ServiceController service in ServiceController.GetServices())
{
string serviceName = service.ServiceName;
string serviceDisplayName = service.DisplayName;
string serviceType = service.ServiceType.ToString();
string status = service.Status.ToString();
ServicesListBox.Items.Add(serviceName +
" " + serviceDisplayName +
serviceType +
" " + status);
}
}

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Gauge for SharePoint
Become a Sponsor