2010-04-13 9 views

Répondre

1

Vérification de l'existence du service, et son statut, pourrait être accompli en exécutant une requête WMI:

// 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"]; 
} 

Pour plus d'informations sur la classe WMI Win32_Service, voir here.