Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
ProjectInstaller.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 using System.Collections;
20 using System.ComponentModel;
21 using System.Configuration.Install;
22 using System.ServiceProcess;
23 using Microsoft.Win32;
24 
25 namespace LuceneMonitorInstall
26 {
30  [RunInstallerAttribute(true)]
31  public class ProjectInstaller : Installer
32  {
33  private ServiceProcessInstaller processInstaller;
34  private ServiceInstaller serviceInstaller;
38  private System.ComponentModel.Container components = null;
39 
41  {
42  // This call is required by the Designer.
43  InitializeComponent();
44 
45  // TODO: Add any initialization after the InitializeComponent call
46  }
47 
51  protected override void Dispose( bool disposing )
52  {
53  if( disposing )
54  {
55  if(components != null)
56  {
57  components.Dispose();
58  }
59  }
60  base.Dispose( disposing );
61  }
62 
63 
64  #region Component Designer generated code
65 
66 
67 
68 
69  private void InitializeComponent()
70  {
71  this.processInstaller = new ServiceProcessInstaller();
72  this.serviceInstaller = new ServiceInstaller();
73  this.processInstaller.Account = ServiceAccount.LocalSystem;
74 
75  this.serviceInstaller.ServiceName = "LuceneMonitor";
76  this.serviceInstaller.StartType = ServiceStartMode.Manual;
77 
78  Installers.Add(this.processInstaller);
79  Installers.Add(this.serviceInstaller);
80 
81  }
82  #endregion
83 
84  public override void Install(IDictionary stateSaver)
85  {
86  RegistryKey system;
87  RegistryKey currentControlSet; //HKEY_LOCAL_MACHINE\Services\CurrentControlSet
88  RegistryKey services; //...\Services
89  RegistryKey service; //...<Service Name>
90 
91  try
92  {
93  //Let the project installer do its job
94  base.Install(stateSaver);
95 
96  system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System"); //Open the HKEY_LOCAL_MACHINE\SYSTEM key
97  currentControlSet = system.OpenSubKey("CurrentControlSet"); //Open CurrentControlSet
98  services = currentControlSet.OpenSubKey("Services"); //Go to the services key
99  service = services.OpenSubKey(this.serviceInstaller.ServiceName, true); //Open the key for serviceInstaller
100 
101  service.SetValue("Description", "Lucene Monitor");
102 
103 
104  }
105  catch(Exception e)
106  {
107  Console.WriteLine("An exception was thrown during service installation:\n" + e.ToString());
108  }
109  }
110 
111  public override void Uninstall(IDictionary savedState)
112  {
113  RegistryKey system;
114  RegistryKey currentControlSet; //HKEY_LOCAL_MACHINE\Services\CurrentControlSet
115  RegistryKey services; //...\Services
116  RegistryKey service; //...<Service Name>
117 
118  try
119  {
120  //Drill down to the service key and open it with write permission
121  system = Registry.LocalMachine.OpenSubKey("System");
122  currentControlSet = system.OpenSubKey("CurrentControlSet");
123  services = currentControlSet.OpenSubKey("Services");
124  service = services.OpenSubKey(this.serviceInstaller.ServiceName, true);
125  service.DeleteSubKeyTree("Description"); //Delete keys created during installation
126 
127  }
128  catch(Exception e)
129  {
130  Console.WriteLine("Exception encountered while uninstalling service:\n" + e.ToString());
131  }
132  finally
133  {
134  //Let the project installer do its job
135  base.Uninstall(savedState);
136  }
137  }
138 
139 
140  }
141 }