ServiceController[] servers = ServiceController.GetServices();
DataTable table = new DataTable();
table.Columns.Add("DisplayName", typeof(string));
table.Columns.Add("Description", typeof(string));
table.Columns.Add("Status", typeof(string));
table.Columns.Add("StartType", typeof(string));
table.Columns.Add("LoginAs", typeof(string));
table.Columns.Add("CanPauseAndContinue", typeof(bool));
table.Columns.Add("CanShutdown", typeof(bool));
table.Columns.Add("CanStop", typeof(bool));
foreach (ServiceController item in servers)
{
string DisplayName = item.DisplayName;
string ServiceName = item.ServiceName;
string Description = "";描述
ServiceControllerStatus Status = item.Status;
string StartType = "";
string LoginAs = "";
bool CanPauseAndContinue = item.CanPauseAndContinue;
bool CanShutdown= item.CanShutdown;
bool CanStop = item.CanStop;
string path = "";//可执行文件的路径
table.Rows.Add(new object[] { DisplayName, Description, Status.ToString() == "Running" ? "已启动" : "", StartType, LoginAs, CanPauseAndContinue, CanShutdown, CanStop });
}