1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| ServiceController controller = new ServiceController();
// Nom de la machine (. pour le poste local)
controller.MachineName = ".";
// Nom du service que l'on veut contrôler
controller.ServiceName = "LeNomDeMonService";
// Ou encore, avec une autre surcharge du constructeur
// ServiceController controller = new ServiceController("LeNomDeMonService", ".");
...
// Arrêt du service
if (controller.Status == ServiceControllerStatus.Running ||
controller.Status == ServiceControllerStatus.Paused)
{
controller.Stop();
}
...
// Démarrage du service
if (controller.Status == ServiceControllerStatus.Stopped)
{
controller.Start();
} |
Partager