Search code examples
c#c++.netwindowswmi

Can I start the Windows Management Instrumentation service programatically?


My application depends on WMI but some users have this turned off by default on their Windows. Is a good idea to start it programatically? if so, how do I do that? Any .NET/C/C++ are welcome


Solution

  • According to the MSDN, if the WMI service is not running it "automatically starts when the first management application or script requests connection to a WMI namespace.".

    So you shouldn't need to start it manually. But if you would need to, the ServiceController class would be one way:

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

    This requires you to reference and import the System.ServiceProcess namespace.