ygdrazil
ygdrazil

Reputation: 17

'ServiceController' does not contain a definition for 'GetServices'

I what to list all services on my computer with a C# form APP. But when i follow what all answers to list all services say i get:

'ServiceController' does not contain a definition for 'GetServices'

All my research leads to:

using ServiceStack.Host;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace myFromApp
{
    public partial class Services : Form
    {
        public Services()
        {
            InitializeComponent();
        }

 private void RefreshServiceBbutton_Click(object sender, EventArgs e)
        {
            ServiceController[] services = ServiceController.GetServices();
           foreach (ServiceController scTemp in scServices)
{
   if (scTemp.Status == ServiceControllerStatus.Running)
   {
      //do stuff with each service(display info and such)
  }
}

   }

   }
}

`

Upvotes: 0

Views: 751

Answers (1)

cesar lachapelle
cesar lachapelle

Reputation: 51

you have to import the namespace System.ServiceProcess and then you can call ServiceController[] services = ServiceController.GetServices(); to obtain the list of services.

Upvotes: 1

Related Questions