Try the following:
using System;
using System.ServiceProcess;
class Program
{
static void Main()
{
// Name of the WMI service
string serviceName = "winmgmt";
// Check if the service is installed
ServiceController[] services = ServiceController.GetServices();
foreach (ServiceController service in services)
{
if (service.ServiceName.Equals(serviceName, StringComparison.OrdinalIgnoreCase))
{
// Check if the service is running and its start type
Console.WriteLine($"Service Name: {service.ServiceName}");
Console.WriteLine($"Status: {service.Status}");
Console.WriteLine($"Start Type: {service.StartType}");
return;
}
}
}
}
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin