示例#1
0
        private void UpdateServerStatus()
        {
            try
            {
                serverStatus = serverController.Status;
            }
            catch (InvalidOperationException)
            {
                serverStatus = null;
            }

            if (serverStatus == null)
            {
                StatusTextBlock.Text = "Not Installed.";
            }
            else
            {
                StatusTextBlock.Text = serverStatus.ToString();

                if (serverStatus == ServiceControllerStatus.Stopped)
                {
                    ServerStartButton.IsEnabled = true;
                    ServerStopButton.IsEnabled  = false;
                }
                else if (serverStatus == ServiceControllerStatus.Running)
                {
                    ServerStartButton.IsEnabled = false;
                    ServerStopButton.IsEnabled  = true;
                }
            }
        }
示例#2
0
        public static ServiceControllerStatus?GetServiceState()
        {
            ServiceControllerStatus?retval = null;

            try
            {
                var sc = new ServiceController(Settings.ServiceName, Settings.ComputerName);
                retval          = sc.Status;
                _OldServiceName = string.Empty;
            }
            catch (Exception)
            {
                try
                {
                    var sc = new ServiceController(Settings.ProductName, Settings.ComputerName);
                    retval          = sc.Status;
                    _OldServiceName = Settings.ProductName;
                }
                catch (Exception ex)
                {
                    Settings.Log?.Debug(ex);
                }
            }
            return(retval);
        }
示例#3
0
 public void ServiceStateChanged(ServiceControllerStatus?status)
 {
     this.Invoke2(() =>
     {
         StartStop.Checked = status == ServiceControllerStatus.Running;
         string title      = "Cistera Screen Capture";
         if (StartStop.Checked)
         {
             notifyIcon.Icon = Icon;
             title          += " started";
         }
         else
         {
             //notifyIcon.Icon = Icon.FromHandle(ImageRoutines.GetGreyScale(Icon.ToBitmap()).GetHicon());
             notifyIcon.Icon = Icon.FromHandle(ImageRoutines.GetInverted(Icon.ToBitmap()).GetHicon());
             if (status != null)
             {
                 title += " stopped";
             }
             else
             {
                 title += " does not exist";
             }
         }
         notifyIcon.Text = title;
     });
 }
示例#4
0
        private void OnFileSystemEvent(FileSystemEventArgs args)
        {
            var message = string.Format("FileSystemEvent: Type = {0}, FilePath = {1}", args.ChangeType, args.FullPath);

            HostLogger.Current.Get("Service").Info(message);
            ServiceControllerStatus?serviceStatus = null;

            try
            {
                var serviceController = new ServiceController(_serviceName);
                serviceStatus = serviceController.Status;
                if (serviceStatus == ServiceControllerStatus.Running)
                {
                    serviceController.Stop();
                }
            }
            catch (Exception e)
            {
                message = string.Format("OnFileSystemEvent: error on stoping service {0}", _serviceName);
                HostLogger.Current.Get("Service").Error(message, e);
            }
            try
            {
                _mailService.SendMessage(args, _serviceName, serviceStatus == null?"uknown":serviceStatus.Value.ToString());
            }
            catch (Exception e)
            {
                message = "Sending mail failed";
                HostLogger.Current.Get("Service").Error(message, e);
            }
        }
示例#5
0
        protected virtual bool CanStop(ServiceControllerStatus?status, out Exception ex)
        {
            var serviceController = _serviceController;

            if (serviceController == null)
            {
                ex = new Exception(ExNotAttachMessage); return(false);
            }

            if (status == ServiceControllerStatus.Running)
            {
                try
                {
                    if (!serviceController.CanStop)
                    {
                        ex = new Exception("служба не может быть оснановлена поскольку данная возможность не поддерживается службой");
                        return(false);
                    }
                }
                catch (Exception except)
                {
                    ex = except;
                    return(false);
                }

                ex = null;
                return(true);
            }

            ex = new Exception(string.Format("служба не может остановиться, поскольку находится в состоянии {0}", status));
            return(false);
        }
示例#6
0
        /// <summary>
        /// 지정된 서버의 서비스 명을 찾아 있을 경우 서비스 상태를 반환
        /// </summary>
        /// <param name="sServiceName">서비스 이름</param>
        /// <param name="sServiceServer">지정된 서버</param>
        /// <returns><see cref="System.ServiceProcess.ServiceControllerStatus"/>서비스 상태 (Nillable)</returns>
        public static ServiceControllerStatus?ServiceStatus(string sServiceName, string sServiceServer)
        {
            ServiceControllerStatus?oResult = null;

            System.Collections.Generic.List <ServiceController> oServiceList = null;
            List <ServiceStatusClass> oResultList = null;

            try
            {
                oResultList  = new List <ServiceStatusClass>();
                oServiceList = ServiceList(sServiceServer);

                foreach (ServiceController oItem in oServiceList)
                {
                    if (oItem != null && oItem.ServiceName.Equals(sServiceName, System.StringComparison.OrdinalIgnoreCase) == true)
                    {
                        oResult = oItem.Status;
                        break;
                    }
                }
            }
            catch (System.Exception) { }
            finally
            {
                if (oServiceList != null)
                {
                    oServiceList.Clear();
                    oServiceList = null;
                }
            }

            return(oResult);
        }
示例#7
0
        private void CheckServices()
        {
            ServiceControllerStatus?status = ServiceHelper.CheckServiceStatus();

            if (status == null)
            {
                InstallService.Enabled   = true;
                UninstallService.Enabled = false;
                StopService.Enabled      = false;
                StartService.Enabled     = false;
                updatePortBt.Enabled     = false;
            }
            else
            {
                InstallService.Enabled   = false;
                updatePortBt.Enabled     = true;
                UninstallService.Enabled = true;
                switch (status)
                {
                case ServiceControllerStatus.ContinuePending:
                    StopService.Enabled  = false;
                    StartService.Enabled = false;
                    break;

                case ServiceControllerStatus.PausePending:
                    StopService.Enabled  = false;
                    StartService.Enabled = false;
                    break;

                case ServiceControllerStatus.Paused:
                    StopService.Enabled  = false;
                    StartService.Enabled = true;
                    break;

                case ServiceControllerStatus.Running:
                    StopService.Enabled  = true;
                    StartService.Enabled = false;
                    break;

                case ServiceControllerStatus.StartPending:
                    StopService.Enabled  = false;
                    StartService.Enabled = false;
                    break;

                case ServiceControllerStatus.StopPending:
                    StopService.Enabled  = false;
                    StartService.Enabled = false;
                    break;

                case ServiceControllerStatus.Stopped:
                    StopService.Enabled  = false;
                    StartService.Enabled = true;
                    break;

                default:
                    break;
                }
            }
        }
示例#8
0
文件: Program.cs 项目: ZiMADE/EmoKill
        private static void StopEmoKillService()
        {
            System.Console.WriteLine();
            System.Console.WriteLine("_________________________________________");
            System.Console.WriteLine();
            System.Console.WriteLine("Stopping EmoKill Service ...");
            System.Console.WriteLine("_________________________________________");
            System.Console.WriteLine();
            ServiceControllerStatus?result = EmoKill.ServiceHelper.StopService();

            System.Console.WriteLine(string.Concat("Service State: ", (result == null) ? "UNKNOWN" : $"{result}"));
            PressEnterToContinue();
        }
示例#9
0
 public void Restart()
 {
     if (OculusUtil.IsElevated)
     {
         Stop();
         Start();
     }
     else
     {
         _temporaryStatus = ServiceControllerStatus.StartPending;
         OculusUtil.ElevateMe(RestartCommand, true);
         _temporaryStatus = null;
     }
 }
示例#10
0
 public void Stop()
 {
     if (OculusUtil.IsElevated)
     {
         _service.Stop();
         _service.WaitForStatus(ServiceControllerStatus.Stopped);
     }
     else
     {
         _temporaryStatus = ServiceControllerStatus.StopPending;
         OculusUtil.ElevateMe(StopCommand, true);
         _temporaryStatus = null;
     }
 }
示例#11
0
        public WatcherResult Watch()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(ServiceName))
                {
                    throw new Exception("ServiceName is incorrect ! NULL or EMPTY");
                }

                var status = WinServiceUtilities.GetServiceStatus(ServiceName);

                bool notify = false;

                if (!_serviceStatus.HasValue || status != _serviceStatus.Value)
                {
                    _serviceStatus = status;
                    if (AnyStatus)
                    {
                        notify = true;
                    }
                    else if ((int)status == Status)
                    {
                        notify = true;
                    }
                }

                if (!notify)
                {
                    return(WatcherResult.NotFound);
                }
                _serviceStatus = status;
                return(WatcherResult.Succeed(ArgumentCollection.New()
                                             .WithArgument(WinServiceWatcherResultArgs.ServiceName, ServiceName)
                                             .WithArgument(WinServiceWatcherResultArgs.Status, status.ToString("G"))));
            }
            catch (Exception exception)
            {
                LoggingService.Error(exception);
                return(WatcherResult.NotFound
                       .WithException(exception));
            }
        }
示例#12
0
        public static ServiceControllerStatus?StopService()
        {
            ServiceControllerStatus?retval = null;

            try
            {
                var sc = new ServiceController(Settings.ServiceName, Settings.ComputerName);
                if (sc.Status == ServiceControllerStatus.Running)
                {
                    sc.Stop();
                    sc.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 1, 0));
                    retval = sc.Status;
                }
            }
            catch (Exception ex)
            {
                Settings.Log?.Error(ex);
            }
            return(retval);
        }
示例#13
0
        protected HowStartType HowStart(ServiceControllerStatus?status, out Exception ex)
        {
            var serviceController = _serviceController;

            if (serviceController == null)
            {
                ex = new Exception(ExNotAttachMessage); return(HowStartType.NoWay);
            }

            if (status == ServiceControllerStatus.Paused)
            {
                try
                {
                    if (!serviceController.CanPauseAndContinue)
                    {
                        ex = new Exception("служба не может быть запущена посколько была приостановлена и не поддерживает возобновление работы");
                        return(HowStartType.NoWay);
                    }
                }
                catch (Exception except)
                {
                    ex = except;
                    return(HowStartType.NoWay);
                }

                ex = null;
                return(HowStartType.Continue);
            }
            else if (status == ServiceControllerStatus.Stopped)
            {
                ex = null;
                return(HowStartType.Start);
            }

            ex = new Exception(string.Format("служба не может начать работу, поскольку находится в состоянии {0}", status));
            return(HowStartType.NoWay);
        }
示例#14
0
 public ServiceStateMessage(ServiceChecker sender, ServiceControllerStatus?status) : base(sender)
 {
     Status = status;
 }
示例#15
0
文件: Program.cs 项目: ZiMADE/EmoKill
        private static int DisplayMenu()
        {
            _ServiceState = EmoKill.ServiceHelper.GetServiceState();
            System.Console.WriteLine("_________________________________________");
            System.Console.WriteLine(@" ______                 _   __ _   _   _ ");
            System.Console.WriteLine(@"|  ____|               | | / /|_| | | | |");
            System.Console.WriteLine(@"| |__   _ __ ___   ___ | |/ /  _  | | | |");
            System.Console.WriteLine(@"|  __| | '_ ` _ ` / _ `|   (  | | | | | |");
            System.Console.WriteLine(@"| |____| | | | | | (_) | |\ \ | | | | | |");
            System.Console.WriteLine(@"|______|_| |_| |_|`___/|_| \_\|_| |_| |_|");
            System.Console.WriteLine("_________________________________________");
            System.Console.WriteLine();
            System.Console.WriteLine("Emotet process killing tool by ZiMADE.");
            System.Console.WriteLine();
            System.Console.WriteLine($"Version:\t{EmoKill.Settings.ProductVersion}");
            System.Console.WriteLine($"Release Date:\t{EmoKill.Settings.ProductDate.ToShortDateString()}");
            System.Console.WriteLine($"URL:\t\t{EmoKill.Settings.ProductRepository}");
            if (_ServiceState == null)
            {
                System.Console.WriteLine($"Service State:\tUNKNOWN");
            }
            else
            {
                System.Console.WriteLine($"Service State:\t{_ServiceState}");
            }
            System.Console.WriteLine("_________________________________________");
            System.Console.WriteLine();
            System.Console.WriteLine("EmoKill-Console Menu");
            System.Console.WriteLine(" 1. Install/Update and start EmoKill as Service");
            if (_ServiceState != null)
            {
                System.Console.WriteLine(" 2. Uninstall EmoKill Service");
            }
            if (_ServiceState == ServiceControllerStatus.Stopped)
            {
                System.Console.WriteLine(" 3. Start EmoKill Service");
            }
            if (_ServiceState == ServiceControllerStatus.Running)
            {
                System.Console.WriteLine(" 4. Stop EmoKill Service");
            }
            System.Console.WriteLine(" 5. Get status of EmoKill Service");
            System.Console.WriteLine(" 6. Show EmoKill Logfile");
            System.Console.WriteLine(" 7. Delete EmoKill Logfile");
            if (_ServiceState == null || _ServiceState == ServiceControllerStatus.Stopped)
            {
                System.Console.WriteLine(" 8. Activate EmoKill in this Console (just for testing)");
            }
            System.Console.WriteLine(" 0. Exit");
            System.Console.WriteLine("_________________________________________");
            System.Console.WriteLine();
            System.Console.Write("Please choose what you wish to do: ");
            var result = System.Console.ReadLine();

            try
            {
                return(Convert.ToInt32(result));
            }
            catch (Exception)
            {
                return(-1);
            }
        }