using System; using System.Collections; using System.Text; using System.ServiceProcess; using System.ComponentModel; using System.Configuration.Install; namespace DaoMqPump2 { [System.ComponentModel.DesignerCategory("Code")] [RunInstaller(true)] public sealed class PumpServiceInstallerProcess : ServiceProcessInstaller { public PumpServiceInstallerProcess() { this.Account = ServiceAccount.LocalSystem; } } [RunInstaller(true)] public sealed class MyServiceInstaller : ServiceInstaller { public MyServiceInstaller() { this.Description = "DAOs multi-transport MQ<->MySQL data pumpe."; this.DisplayName = "DAO MQ Pump v2"; this.ServiceName = "DaoMqPump2"; 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(DaoMqPump2.MainProgram).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); } } } }