Exemple #1
0
        public IHttpActionResult UpdateStatus([FromUri] string serviceName = null, [FromUri] bool?start = null)
        {
            if (string.IsNullOrWhiteSpace(serviceName))
            {
                return(BadRequest($"Missing required value for querystring '{nameof(serviceName)}'."));
            }

            if (start == null)
            {
                return(BadRequest($"Missing required value for querystring '{nameof(start)}'."));
            }

            bool exists = _windowsServices.Exists(serviceName);

            if (!exists)
            {
                return(NotFound());
            }

            if (start.Value)
            {
                _windowsServices.Start(serviceName);
            }
            else
            {
                _windowsServices.Stop(serviceName);
            }

            return(GetStatus(serviceName));
        }
        private bool UninstallWindowsService(HostArguments args)
        {
            bool windowsServiceExists = _windowsServices.Exists(WindowsServiceName);

            if (CommandIs(args, "uninstall"))
            {
                if (windowsServiceExists)
                {
                    _windowsServices.Stop(WindowsServiceName);
                    _windowsServices.Uninstall(WindowsServiceName);
                }

                return(true);
            }

            return(false);
        }