using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.ServiceProcess; using System.Configuration.Install; namespace WindowsService { /// <summary> /// This is the class for my Service /// </summary> public class MyService : System.ServiceProcess.ServiceBase { public MyService() { InitializeComponents(); // TODO: Add any further initialization code } private void InitializeComponents() { this.ServiceName = "MyService"; } /// <summary> /// This method starts the service. /// </summary> public static void Main() { System.ServiceProcess.ServiceBase.Run(new System.ServiceProcess.ServiceBase[] { new MyService() // To run more than one service you have to add them here }); } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { // TODO: Add cleanup code here (if required) base.Dispose(disposing); } /// <summary> /// Start this service. /// </summary> protected override void OnStart(string[] args) { // TODO: Add start code here (if required) // to start your service. EventLog.WriteEntry("Servicio Iniciado"); } /// <summary> /// Stop this service. /// </summary> protected override void OnStop() { // TODO: Add tear-down code here (if required) // to stop your service. EventLog.WriteEntry("Servicio Detenido"); } } } [RunInstallerAttribute(true)] public class ProjectInstaller : Installer { public ProjectInstaller() { ServiceProcessInstaller spi = new ServiceProcessInstaller(); spi.Account = ServiceAccount.LocalSystem; ServiceInstaller si = new ServiceInstaller(); si.ServiceName = "Hello Service Template"; si.StartType = ServiceStartMode.Automatic; Installers.AddRange(new Installer[] {spi, si}); } }using: