using System; using System.Collections; using System.Text; using System.ServiceProcess; using System.ComponentModel; using System.Configuration.Install; namespace MQFilter { [System.ComponentModel.DesignerCategory("Code")] [RunInstaller(true)] public sealed class FilterServiceInstallerProcess : ServiceProcessInstaller { public FilterServiceInstallerProcess() { this.Account = ServiceAccount.LocalSystem; } } [RunInstaller(true)] public sealed class MyServiceInstaller : ServiceInstaller { public MyServiceInstaller() { this.Description = "DAOs MQ Filter Transport"; this.DisplayName = "DAO MQFilter"; this.ServiceName = "DaoMqFilter"; this.StartType = System.ServiceProcess.ServiceStartMode.Manual; } public static void DoInstall(bool undo, string[] args) { try { Console.WriteLine(undo ? "uninstalling" : "installing"); using (AssemblyInstaller inst = new AssemblyInstaller(typeof(FilterMainProgram).Assembly, args)) { IDictionary state = new Hashtable(); inst.UseNewContext = true; try { if (undo) { inst.Uninstall(state); } else { inst.Install(state); inst.Commit(state); } } catch { try { inst.Rollback(state); } catch { } throw; } } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); } } } }