Example #1
0
        internal void Stop(Business.Server server, SetStatusLabelDelegate setStatusLabelDelegate)
        {
            string userName = null;
            string password = null;

            if (server.UseImpersonation == true)
            {
                userName = server.UserName;
                password = Encryption.Decrypt(server.Password);
            }

            List <WmiService> services = WmiService.GetAllServices(server.ServerName, userName, password, "Name = '" + this.ServiceName + "'");

            foreach (WmiService service in services)
            {
                setStatusLabelDelegate("Stopping " + service.DisplayName);

                ReturnValue returnValue;

                if (service.State != State.Stopped)
                {
                    if ((returnValue = WmiService.Stop(server.ServerName, userName, password, service.Name)) != ReturnValue.Success)
                    {
                        throw new Exception("Couldn't stop service: " + service.DisplayName + ", the result was: " + returnValue);
                    }
                }
            }

            setStatusLabelDelegate("Ready.");
        }
Example #2
0
        internal void RemoveFromServer(Business.Server server, SetStatusLabelDelegate setStatusLabelDelegate)
        {
            string userName = null;
            string password = null;

            if (server.UseImpersonation == true)
            {
                userName = server.UserName;
                password = Encryption.Decrypt(server.Password);
            }

            List <WmiService> services = WmiService.GetAllServices(server.ServerName, userName, password, "Name = '" + this.ServiceName + "'");

            // Saftey in case we get too many services back, we don't want to delete them all...
            if (services.Count > 20)
            {
                StringBuilder servicesToRemove = new StringBuilder("This action will remove the following services, are you sure?\n");
                foreach (WmiService service in services)
                {
                    servicesToRemove.AppendFormat("\n{0}", service.DisplayName);
                }

                if (MessageBox.Show(servicesToRemove.ToString(), "Are you sure?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
                {
                    return;
                }
            }


            foreach (WmiService service in services)
            {
                setStatusLabelDelegate("Removing " + service.DisplayName);

                ReturnValue returnValue;

                if (service.State != State.Stopped)
                {
                    if ((returnValue = WmiService.Stop(server.ServerName, userName, password, service.Name)) != ReturnValue.Success)
                    {
                        throw new Exception("Couldn't stop service: " + service.DisplayName + ", the result was: " + returnValue);
                    }
                }

                if ((returnValue = WmiService.Delete(server.ServerName, userName, password, service.Name)) != ReturnValue.Success)
                {
                    throw new Exception("Couldn't remove service: " + service.DisplayName + ", the result was: " + returnValue);
                }
            }

            setStatusLabelDelegate("Ready.");
        }