In this post will show about how to get list all of window server to display or show in ListView control in C# programming.
Source code below show about get all all window service to display in ListView
using System.ServiceProcess; ServiceController[] services = ServiceController.GetServices(); foreach (ServiceController service in services) { ListViewItem item = new ListViewItem(); item.Text = service.ServiceName; item.SubItems.Add(service.DisplayName); item.SubItems.Add(service.Status.ToString()); this.listViewShowService.Items.Add(item); }
Source code below show about get window server by specific service name and checking its status
using System.ServiceProcess; ServiceController service = new ServiceController("ServiceName"); if (service.Status == ServiceControllerStatus.Running) { // Process running } else if (service.Status == ServiceControllerStatus.Stopped) { // Process stoped } else if (service.Status == ServiceControllerStatus.Paused) { // Process paused }