133 lines
4.1 KiB
C#
133 lines
4.1 KiB
C#
// Copyright (c) 2008-2018 schick Informatik
|
|
// Description:
|
|
//
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Configuration.Install;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.ServiceProcess;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace bsmd.AISService
|
|
{
|
|
static class Program
|
|
{
|
|
/// <summary>
|
|
/// The main entry point for the application.
|
|
/// </summary>
|
|
public static int Main(string[] args)
|
|
{
|
|
if (Environment.UserInteractive)
|
|
{
|
|
if (args.Length > 0)
|
|
{
|
|
string arg = args[0].ToLowerInvariant().Substring(0, 2);
|
|
switch (arg)
|
|
{
|
|
case "/i": // install
|
|
return InstallService();
|
|
|
|
case "/u": // uninstall
|
|
return UninstallService();
|
|
|
|
default: // unknown option
|
|
Console.WriteLine("Argument not recognized: {0}", args[0]);
|
|
Console.WriteLine(string.Empty);
|
|
DisplayUsage();
|
|
return 1;
|
|
}
|
|
}
|
|
else if(Debugger.IsAttached)
|
|
{
|
|
AISService aisService = new AISService();
|
|
aisService.DebugStart();
|
|
} else
|
|
{
|
|
DisplayUsage();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ServiceBase[] ServicesToRun;
|
|
ServicesToRun = new ServiceBase[]
|
|
{
|
|
new AISService()
|
|
};
|
|
ServiceBase.Run(ServicesToRun);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
private static void DisplayUsage()
|
|
{
|
|
//..
|
|
}
|
|
|
|
private static int InstallService()
|
|
{
|
|
var service = new AISService();
|
|
|
|
try
|
|
{
|
|
// perform specific install steps for our queue service.
|
|
//service.InstallService();
|
|
|
|
// install the service with the Windows Service Control Manager (SCM)
|
|
ManagedInstallerClass.InstallHelper(new string[] { Assembly.GetExecutingAssembly().Location });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (ex.InnerException != null && ex.InnerException.GetType() == typeof(Win32Exception))
|
|
{
|
|
Win32Exception wex = (Win32Exception)ex.InnerException;
|
|
Console.WriteLine("Error(0x{0:X}): Service already installed!", wex.ErrorCode);
|
|
return wex.ErrorCode;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine(ex.ToString());
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
private static int UninstallService()
|
|
{
|
|
var service = new AISService();
|
|
|
|
try
|
|
{
|
|
// perform specific uninstall steps for our queue service
|
|
//service.UninstallService();
|
|
|
|
// uninstall the service from the Windows Service Control Manager (SCM)
|
|
ManagedInstallerClass.InstallHelper(new string[] { "/u", Assembly.GetExecutingAssembly().Location });
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (ex.InnerException.GetType() == typeof(Win32Exception))
|
|
{
|
|
Win32Exception wex = (Win32Exception)ex.InnerException;
|
|
Console.WriteLine("Error(0x{0:X}): Service not installed!", wex.ErrorCode);
|
|
return wex.ErrorCode;
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine(ex.ToString());
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
}
|