我可以以编程方式启动 Windows Management Instrumentation 服务吗?

Can I start the Windows Management Instrumentation service programatically?

我的应用程序依赖于 WMI,但一些用户在他们的 Windows 上默认关闭了它。以编程方式启动它是个好主意吗?如果是这样,我该怎么做?欢迎任何 .NET/C/C++

根据MSDN,如果WMI服务不是运行它"automatically starts when the first management application or script requests connection to a WMI namespace.".

因此您不需要手动启动它。但是,如果您需要,ServiceController class 将是一种方式:

using(ServiceController sc = new ServiceController("winmgmt"))
{
    sc.Start();
}

这需要您引用并导入 System.ServiceProcess 命名空间。