Programmatically Check if Windows Messaging is installed?

Is there an easy way to determine if the messaging component is installed and the service is running on Windows using C #?

+2


a source to share


1 answer


Checking for the existence of a service and its status can be done by executing a WMI query:

// Setup the query
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
                    "SELECT * FROM Win32_Service WHERE Name = 'Blah'");

// Execute the query and enumerate the objects
foreach (ManagementObject queryObj in searcher.Get())
{
   // examine the query results to find the info you need.  For example:
    string name = (string)queryObj["Name"];
    bool started = (bool)queryObj["Started"];
    string status = (string)queryObj["Status"];
}

      



For more information on the WMI Win32_Service class, see here.

+1


a source







All Articles