我知道如何使用C#表单应用程序列出我计算机上的所有服务。但是当我按照所有答案列出所有服务时,我会得到:
'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)
}
}
}
}
}`
发布于 2019-10-08 06:00:59
您必须导入名称空间System.ServiceProcess,然后才能调用ServiceController[] services = ServiceController.GetServices();来获取服务列表。
https://stackoverflow.com/questions/58276292
复制相似问题