From 8851dc1212e5fc72e55f614ce965997f366922f7 Mon Sep 17 00:00:00 2001 From: vfedosevich Date: Wed, 27 Nov 2013 17:39:00 +0300 Subject: [PATCH] fixed bug reinstall scheduler service --- .../CustomAction.cs | 24 +++++++++++++++++-- .../Common/SecurityUtils.cs | 14 ++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/WebsitePanel.Installer/Sources/WebsitePanel.SchedulerServiceInstaller/CustomAction.cs b/WebsitePanel.Installer/Sources/WebsitePanel.SchedulerServiceInstaller/CustomAction.cs index f5655efd..eff618a7 100644 --- a/WebsitePanel.Installer/Sources/WebsitePanel.SchedulerServiceInstaller/CustomAction.cs +++ b/WebsitePanel.Installer/Sources/WebsitePanel.SchedulerServiceInstaller/CustomAction.cs @@ -35,6 +35,7 @@ using System.Linq; using System.ServiceProcess; using System.Text.RegularExpressions; using Microsoft.Deployment.WindowsInstaller; +using WebsitePanel.Setup; namespace WebsitePanel.SchedulerServiceInstaller { @@ -72,11 +73,19 @@ namespace WebsitePanel.SchedulerServiceInstaller { try { - if (!ServiceController.GetServices().Any(s => s.DisplayName.Equals("WebsitePanel Scheduler", StringComparison.CurrentCultureIgnoreCase))) + var schedulerService = + ServiceController.GetServices().FirstOrDefault( + s => s.DisplayName.Equals("WebsitePanel Scheduler", StringComparison.CurrentCultureIgnoreCase)); + + if (schedulerService != null) { - ManagedInstallerClass.InstallHelper(new[] {"/i", Path.Combine(installFolder, "WebsitePanel.SchedulerService.exe")}); + StopService(schedulerService.ServiceName); + + SecurityUtils.DeleteService(schedulerService.ServiceName); } + ManagedInstallerClass.InstallHelper(new[] { "/i", Path.Combine(installFolder, "WebsitePanel.SchedulerService.exe") }); + StartService("WebsitePanel Scheduler"); } catch (Exception) @@ -122,6 +131,17 @@ namespace WebsitePanel.SchedulerServiceInstaller } } + private static void StopService(string serviceName) + { + var sc = new ServiceController(serviceName); + + if (sc.Status == ServiceControllerStatus.Running) + { + sc.Stop(); + sc.WaitForStatus(ServiceControllerStatus.Stopped); + } + } + private static void StartService(string serviceName) { var sc = new ServiceController(serviceName); diff --git a/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Common/SecurityUtils.cs b/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Common/SecurityUtils.cs index e69f9bbb..668e7875 100644 --- a/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Common/SecurityUtils.cs +++ b/WebsitePanel.Installer/Sources/WebsitePanel.Setup/Common/SecurityUtils.cs @@ -27,6 +27,7 @@ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using System; +using System.IO; using System.Text; using System.DirectoryServices; using System.DirectoryServices.ActiveDirectory; @@ -1099,7 +1100,18 @@ namespace WebsitePanel.Setup } #endregion - } + + #region Windows Services + + public static void DeleteService(string serviceName) + { + var wmiService = wmi.GetObject(String.Format("Win32_Service.Name='{0}'", serviceName)); + + wmiService.Delete(); + } + + #endregion + } #region Enums [Flags]