rendered paste body//ServiceMgr.cs:
AssemblyInstaller asmInstaller = new AssemblyInstaller(executableLocation, new string[] { "/LogToConsole=false" });
Hashtable rollback = new Hashtable();
if (CheckExistingService(serviceName))
{
return String.Format("The service {0} already exists!\n", serviceName);
}
try
{
asmInstaller.Install(rollback);
asmInstaller.Commit(rollback);
ConfigMgr.SetSetting("ExeLocation", executableLocation);
return String.Format("Service {0} successfully installed! Service is pointing to: {1}\n", serviceName, asmInstaller.Path);
}
catch (Exception)
{
asmInstaller.Rollback(rollback);
return "An error occured while installing the service! Rolling back changes..\n";
}
//ServerServiceInstaller.cs:
[RunInstaller(true)]
public class GameServerServiceInstaller : Installer
{
private ServiceInstaller m_gameServerServiceInstaller;
private ServiceProcessInstaller m_gameServerServiceProcessInstaller;
public GameServerServiceInstaller()
{
// Instantiate installers for process and services.
m_gameServerServiceProcessInstaller = new ServiceProcessInstaller();
m_gameServerServiceProcessInstaller.Account = ServiceAccount.NetworkService;
m_gameServerServiceInstaller = new ServiceInstaller();
m_gameServerServiceInstaller.StartType = ServiceStartMode.Automatic;
m_gameServerServiceInstaller.ServiceName = ServerOptions.ApplicationSetting("ServiceName", "DOL");
Installers.Add(m_gameServerServiceProcessInstaller);
Installers.Add(m_gameServerServiceInstaller);
}
public override void Install(IDictionary stateServer)
{
Context.Parameters["assemblyPath"] = Assembly.GetEntryAssembly().Location;
base.Install(stateServer);
}