public void TabClosed() { Configuration.WebMediaPortalHosting.Port = Int32.Parse(txtPort.Text); Configuration.WebMediaPortalHosting.EnableTLS = cbHTTPS.IsChecked.GetValueOrDefault(false); Configuration.WebMediaPortalHosting.PortTLS = Int32.Parse(txtHTTPSPort.Text); Configuration.Save(); // restart if (UacServiceHelper.IsAdmin()) { Task.Factory.StartNew(() => { try { var wsh = new WindowsServiceHandler("MPExtended WebMediaPortal"); wsh.Execute(ServiceCommand.Restart); } catch (Exception ex) { Log.Warn("Failed to restart WebMediaPortal hosting process", ex); } }); } else { UacServiceHelper.RunUacServiceHandler("/command:webmphosting /action:restart"); } }
private void btnStartStopService_Click(object sender, RoutedEventArgs e) { if (!UacServiceHelper.IsAdmin()) { Log.Debug("StartStopService: no admin rights, use UacServiceHandler"); switch (mServiceController.Status) { case ServiceControllerStatus.Stopped: UacServiceHelper.StartService(); break; case ServiceControllerStatus.Running: UacServiceHelper.StopService(); break; } } else { Log.Debug("StartStopService: have admin rights, start/stop ourselves"); switch (mServiceController.Status) { case ServiceControllerStatus.Stopped: mServiceController.Start(); break; case ServiceControllerStatus.Running: mServiceController.Stop(); break; } } }
/// <summary> /// Stops the installed MP2 Server Service. /// </summary> public bool StopServerService() { try { if (!UacServiceHelper.IsAdmin()) { return(UacServiceHelper.StopService()); } using (var serviceController = new ServiceController(SERVER_SERVICE_NAME)) { switch (serviceController.Status) { case ServiceControllerStatus.Running: serviceController.Stop(); break; case ServiceControllerStatus.StopPending: break; case ServiceControllerStatus.Stopped: return(true); default: return(false); } serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(60)); UpdateServerStatus(); return(serviceController.Status == ServiceControllerStatus.Stopped); } } catch (Exception ex) { ServiceRegistration.Get <ILogger>().Error("Stopping MP2 Server Service failed.", ex); UpdateServerStatus(); return(false); } }