我要使用 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)
}
}
}
}
}
`