Узнать статус Windows службы

Messages
1,679
Reaction score
288
Website
tehadm.ru
Данный метод позвляет узнать статус Windows служб.
C#:
public static String GetWindowsServiceStatus(String SERVICENAME)
        {
            ServiceController sc = new ServiceController(SERVICENAME);

            switch (sc.Status)
            {
                case ServiceControllerStatus.Running:
                    return "Running";
                case ServiceControllerStatus.Stopped:
                    return "Stopped";
                case ServiceControllerStatus.Paused:
                    return "Paused";
                case ServiceControllerStatus.StopPending:
                    return "Stopping";
                case ServiceControllerStatus.StartPending:
                    return "Starting";
                default:
                    return "Status Changing";
            }
        }

fb732-1.png
 
Last edited:
Back
Top