in SimpleRemoteConsole/Program.cs [26:106]
static void Main(string[] args)
{
if (args.Contains("--SuppressUserWarning") || args.Contains("--start-service"))
{
Console.WriteLine("User warning suppressed.");
}
else if (CheckUserWarning())
{
Console.WriteLine("User warning acknowledged. Proceeding...");
}
else
{
Console.WriteLine("Aborting - user declined to proceed after warning.");
return;
}
const string svcName = "SimpleDUTRemote-Service";
List<string> argsList = new List<string>(args);
ServiceInfo info = new ServiceInfo()
{
ServiceName = svcName,
DisplayName = svcName,
BinaryPath = Assembly.GetEntryAssembly().Location,
ServiceArgs = argsList.ToArray(),
StartHandler = InitializeServer,
StopHandler = () => { },
StartType = StartType.SERVICE_DEMAND_START
};
try
{
// installs and launches the service. It doesn't fail
// if the service is already installed and does not
// uninstall then reinstall the service; it will just launch
// the existing service
if (args.Contains("--install-service"))
{
// change the argument from install to start so
// that when the service is started and this method
// is re-entered, it takes the start service path
argsList.Remove("--install-service");
argsList.Add("--start-service");
info.ServiceArgs = argsList.ToArray();
var svcStartIndex = argsList.IndexOf("--service-start-type");
if (svcStartIndex != -1 && argsList[svcStartIndex + 1].ToLower() == "auto")
{
info.StartType = StartType.SERVICE_AUTO_START;
}
Service svc = new Service(info);
svc.CreateService();
}
else if (args.Contains("--uninstall-service"))
{
Service svc = new Service(info);
svc.RemoveService();
}
else if (args.Contains("--start-service"))
{
Service svc = new Service(info);
svc.StartService();
}
// if there are no service related commands, we launch the server as usual
else
{
InitializeServer(args);
Console.CancelKeyPress += HandleCancelEvent;
// wait for Ctrl+C
stopEvt.WaitOne();
Console.WriteLine("Stopping Server.");
}
}
catch (Exception e)
{
Console.WriteLine("Exception occurred: " + e.Message);
Console.WriteLine("Exiting...");
}
}