Ejemplo n.º 1
0
        public static NativeMethods.ServiceStatusInfo ReadServiceStatus(SafeServiceHandle serviceHandle)
        {
            NativeMethods.ServiceStatusInfo ServiceStatus = default;

            if (!NativeMethods.QueryServiceStatus(serviceHandle, ref ServiceStatus))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            return(ServiceStatus);
        }
Ejemplo n.º 2
0
        private void ControlService(uint dwAccess, uint dwControl)
        {
            using SafeServiceHandle ServiceManager = ServiceHelper.OpenServiceManager(
                      MachineName,
                      NativeMethods.SC_MANAGER_CONNECT);

            using SafeServiceHandle ServiceHandle = ServiceHelper.OpenService(
                      ServiceManager,
                      ServiceName,
                      dwAccess);

            NativeMethods.ServiceStatusInfo Status = default;

            if (!NativeMethods.ControlService(ServiceHandle, dwControl, ref Status))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            State = Status.dwCurrentState;
        }
Ejemplo n.º 3
0
        private void RefreshStatus(SafeServiceHandle serviceHandle)
        {
            NativeMethods.ServiceStatusInfo Status = ServiceHelper.ReadServiceStatus(serviceHandle);

            State = Status.dwCurrentState;
        }