Esempio n. 1
0
        private void EnableServicesWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // Get Services Collection...
            ServiceController[] serviceController;
            serviceController = ServiceController.GetServices();

            // Loop through and check for a particular Service...
            foreach (ServiceController scTemp in serviceController)
            {
                switch (scTemp.DisplayName)
                {
                case "Windows Update":
                    RestartService(scTemp.DisplayName, 5000);
                    break;

                case "Automatic Updates":
                    RestartService(scTemp.DisplayName, 5000);
                    break;

                default:
                    break;
                }
            }

            // Check for iAutomaticUpdates.ServiceEnabled...
            IAutomaticUpdates iAutomaticUpdates = new AutomaticUpdates();

            if (!iAutomaticUpdates.ServiceEnabled)
            {
                iAutomaticUpdates.EnableService();
            }
        }
Esempio n. 2
0
        public static void EnableUpdateServices()
        {
            IAutomaticUpdates updates = new AutomaticUpdates();

            if (!updates.ServiceEnabled)
            {
                Console.WriteLine("Not all updates services where enabled. Enabling Now" + updates.ServiceEnabled);
                updates.EnableService();
                Console.WriteLine("Service enable success");
            }
        }
        /// <summary>
        /// Check for Windows Update Service running
        /// </summary>
        public static void EnableUpdateServices()
        {
            Console.WriteLine("Checking Windows Update Service is running");

            IAutomaticUpdates updates = new AutomaticUpdates();

            if (!updates.ServiceEnabled)
            {
                Console.WriteLine("Windows update service was not enabled. Enabling Now" + updates.ServiceEnabled);
                updates.EnableService();
                Console.WriteLine("Service enabled");
            }
            else
            {
                Console.WriteLine("Running");
            }
        }
Esempio n. 4
0
        int EnableServices(out string strError)
        {
            strError = "";
            ServiceController[] controllers = ServiceController.GetServices();

            foreach (ServiceController controller in controllers)
            {
                switch (controller.DisplayName)
                {
                case "Windows Update":
                    RestartService(controller.DisplayName, 5000);
                    break;

                case "Automatic Updates":
                    RestartService(controller.DisplayName, 5000);
                    break;

                default:
                    break;
                }
            }

            // Check for iAutomaticUpdates.ServiceEnabled...
            IAutomaticUpdates iAutomaticUpdates = new AutomaticUpdates();

            if (!iAutomaticUpdates.ServiceEnabled)
            {
                try
                {
                    iAutomaticUpdates.EnableService();
                }
                catch (System.InvalidCastException ex)
                {
                    strError = ex.Message;
                    return(-1);
                }
            }

            return(0);
        }
Esempio n. 5
0
        int EnableServices(out string strError)
        {
            strError = "";
            ServiceController[] controllers = ServiceController.GetServices();

            foreach (ServiceController controller in controllers)
            {
                switch (controller.DisplayName)
                {
                    case "Windows Update":
                        RestartService(controller.DisplayName, 5000);
                        break;
                    case "Automatic Updates":
                        RestartService(controller.DisplayName, 5000);
                        break;
                    default:
                        break;
                }
            }

            // Check for iAutomaticUpdates.ServiceEnabled...
            IAutomaticUpdates iAutomaticUpdates = new AutomaticUpdates();
            if (!iAutomaticUpdates.ServiceEnabled)
            {
                try
                {
                    iAutomaticUpdates.EnableService();
                }
                catch (System.InvalidCastException ex)
                {
                    strError = ex.Message;
                    return -1;
                }
            }

            return 0;
        }
Esempio n. 6
0
        int EnableServices(out string strError)
        {
            strError = "";
            // Get Services Collection...
            ServiceController[] serviceController;
            serviceController = ServiceController.GetServices();

            // Loop through and check for a particular Service...
            foreach (ServiceController scTemp in serviceController)
            {
                switch (scTemp.DisplayName)
                {
                    case "Windows Update":
                        RestartService(scTemp.DisplayName, 5000);
                        break;
                    case "Automatic Updates":
                        RestartService(scTemp.DisplayName, 5000);
                        break;
                    default:
                        break;
                }
            }

            // Check for iAutomaticUpdates.ServiceEnabled...
            IAutomaticUpdates iAutomaticUpdates = new AutomaticUpdates();
            if (!iAutomaticUpdates.ServiceEnabled)
            {
                iAutomaticUpdates.EnableService();
            }

            return 0;
        }