Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveHiveEngine/HeuristicLab.Clients.Hive.Slave.WindowsService/3.3/ProjectInstaller.cs @ 11063

Last change on this file since 11063 was 7131, checked in by ascheibe, 13 years ago

#1672 try to stop the slave service before uninstalling it

File size: 1.4 KB
Line 
1using System;
2using System.Collections;
3using System.ComponentModel;
4using System.ServiceProcess;
5
6
7namespace HeuristicLab.Clients.Hive.SlaveCore.WindowsService {
8  [RunInstaller(true)]
9  public partial class ProjectInstaller : System.Configuration.Install.Installer {
10    public ProjectInstaller() {
11      InitializeComponent();
12    }
13
14    protected override void OnBeforeUninstall(IDictionary savedState) {
15      base.OnBeforeUninstall(savedState);
16
17      //try to shutdown the service before uninstalling it
18      using (var serviceController = new ServiceController(this.serviceInstaller1.ServiceName, Environment.MachineName)) {
19        try {
20          serviceController.Stop();
21        }
22        catch { }
23      }
24    }
25
26    protected override void OnAfterInstall(IDictionary savedState) {
27      base.OnAfterInstall(savedState);
28
29      //try to create an event log     
30      try {
31        if (!System.Diagnostics.EventLog.SourceExists("HLHive")) {
32          System.Diagnostics.EventLog.CreateEventSource("HLHive", "HiveSlave");
33        }
34      }
35      catch { }
36
37      //try to start the service after installation
38      using (var serviceController = new ServiceController(this.serviceInstaller1.ServiceName, Environment.MachineName)) {
39        try {
40          serviceController.Start();
41        }
42        catch { }
43      }
44    }
45  }
46}
Note: See TracBrowser for help on using the repository browser.