private static void Install(bool install, ServiceInfo serviceInfo) { using (TransactedInstaller transactedInstaller = new TransactedInstaller()) { using (System.Configuration.Install.Installer installer = CreateInstaller(serviceInfo)) { transactedInstaller.Installers.Add(installer); string path = string.Format("/assemblypath={0}", Assembly.GetEntryAssembly().Location); transactedInstaller.Context = new InstallContext("", new[] { path }); if (install) transactedInstaller.Install(new Hashtable()); else transactedInstaller.Uninstall(null); } } }
private static System.Configuration.Install.Installer CreateInstaller(ServiceInfo serviceInfo) { System.Configuration.Install.Installer installer = new System.Configuration.Install.Installer(); ServiceInstaller serviceInstaller = new ServiceInstaller(); ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller(); serviceInstaller.Description = serviceInfo.Description; serviceInstaller.StartType = serviceInfo.ServiceStartMode; serviceInstaller.DisplayName = serviceInfo.DisplayName; serviceInstaller.ServiceName = serviceInfo.ServiceName; if (serviceInfo.DependsOn != null && serviceInfo.DependsOn.Length > 0) serviceInstaller.ServicesDependedOn = serviceInfo.DependsOn; serviceProcessInstaller.Account = serviceInfo.ServiceAccount; serviceProcessInstaller.Username = serviceInfo.UserName; serviceProcessInstaller.Password = serviceInfo.Password; installer.Installers.Add(serviceProcessInstaller); installer.Installers.Add(serviceInstaller); return installer; }
public Service(ServiceInfo serviceInfo) { ServiceTasks = new List <ServiceTask>(); ServiceInfo = serviceInfo; }
public Service(string serviceName) { ServiceTasks = new List <ServiceTask>(); ServiceInfo = new ServiceInfo(serviceName); }
public Service(ServiceInfo serviceInfo) { ServiceTasks = new List<ServiceTask>(); ServiceInfo = serviceInfo; }
public Service(string serviceName) { ServiceTasks = new List<ServiceTask>(); ServiceInfo = new ServiceInfo(serviceName); }
public static void UnInstall(ServiceInfo serviceInfo) { Install(false, serviceInfo); }
public static void Install(ServiceInfo serviceInfo) { Install(true,serviceInfo); }