fixed bug reinstall scheduler service

This commit is contained in:
vfedosevich 2013-11-27 17:39:00 +03:00
parent 2b68bfb8bf
commit 8851dc1212
2 changed files with 35 additions and 3 deletions

View file

@ -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);

View file

@ -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]