Exemplo n.º 1
0
        // Service start, if the service isn't active, we run it. Otherwise, nothing is done.
        /// <summary>
        /// Starting Service
        /// </summary>
        private static void StartService(){
            ImpersonateUser iu = new ImpersonateUser();
            
            iu.Impersonate(@".", "Axel", Settings.Default.Password);

            using (var controller = new ServiceController("RedXService")){
                ServiceControllerPermission scp = new ServiceControllerPermission(ServiceControllerPermissionAccess.Control, ".", "RedXService");
                scp.Assert();

                controller.Refresh();
                if (controller.Status != ServiceControllerStatus.Running){
                    controller.Start();
                }
                controller.WaitForStatus(ServiceControllerStatus.StartPending);
                controller.WaitForStatus(ServiceControllerStatus.Running);

                controller.Refresh();
            }
  
            iu.Undo();
        }
Exemplo n.º 2
0
        // Service start, if the service isn't active, we run it. Otherwise, nothing is done.
        /// <summary>
        /// Starting Service
        /// </summary>
        private static void StartService()
        {
            ImpersonateUser iu = new ImpersonateUser();

            iu.Impersonate(@".", "Axel", Settings.Default.Password);

            using (var controller = new ServiceController("RedXService")){
                ServiceControllerPermission scp = new ServiceControllerPermission(ServiceControllerPermissionAccess.Control, ".", "RedXService");
                scp.Assert();

                controller.Refresh();
                if (controller.Status != ServiceControllerStatus.Running)
                {
                    controller.Start();
                }
                controller.WaitForStatus(ServiceControllerStatus.StartPending);
                controller.WaitForStatus(ServiceControllerStatus.Running);

                controller.Refresh();
            }

            iu.Undo();
        }