initialize
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration.Install;
|
||||
using System.Diagnostics;
|
||||
using System.ServiceProcess;
|
||||
using com.itac.mes.tools;
|
||||
|
||||
|
||||
namespace com.itac.mes.proxy.winservice
|
||||
{
|
||||
[RunInstaller(true)]
|
||||
public class WindowsServiceInstaller : Installer
|
||||
{
|
||||
/// <summary>
|
||||
/// Public Constructor for WindowsServiceInstaller.
|
||||
/// - Put all of your Initialization code here.
|
||||
/// </summary>
|
||||
public WindowsServiceInstaller()
|
||||
{
|
||||
ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
|
||||
ServiceInstaller serviceInstaller = new ServiceInstaller();
|
||||
|
||||
//# Service Account Information
|
||||
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
|
||||
serviceProcessInstaller.Username = null;
|
||||
serviceProcessInstaller.Password = null;
|
||||
|
||||
//# Service Information
|
||||
serviceInstaller.DisplayName = Constants.SERVICE_NAME;
|
||||
serviceInstaller.StartType = ServiceStartMode.Automatic;
|
||||
|
||||
//# This must be identical to the WindowsService.ServiceBase name
|
||||
//# set in the constructor of WindowsService.cs
|
||||
serviceInstaller.ServiceName = Constants.SERVICE_NAME;
|
||||
this.Installers.Add(serviceProcessInstaller);
|
||||
this.Installers.Add(serviceInstaller);
|
||||
}
|
||||
|
||||
public override void Install(System.Collections.IDictionary stateSaver)
|
||||
{
|
||||
base.Install(stateSaver);
|
||||
ServiceController controller = new ServiceController(Constants.SERVICE_NAME);
|
||||
try
|
||||
{
|
||||
controller.Start();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (!EventLog.SourceExists(Constants.SERVICE_NAME))
|
||||
{
|
||||
EventLog.CreateEventSource(Constants.SERVICE_NAME, Constants.LOGGER);
|
||||
}
|
||||
EventLog.WriteEntry(Constants.SERVICE_NAME, "@The service could not be started. Error: " + e.Message, EventLogEntryType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user