0

我要使用 C# 表单 APP 列出计算机上的所有服务。但是,当我遵循列出所有服务的所有答案时,我得到了:

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

我所有的研究导致:

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)
  }
}

   }

   }
}

`

4

1 回答 1

1

您必须导入命名空间System.ServiceProcess,然后才能调用ServiceController[] services = ServiceController.GetServices();以获取服务列表。

于 2019-10-07T22:00:58.680 回答