From edf030afaaa3f6d2b0747ed90db458dc7e7f33d7 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Thu, 27 Sep 2018 21:08:47 -0400 Subject: [PATCH] Cleanup Service.Program.OnExecute --- src/Tgstation.Server.Host.Service/Program.cs | 41 +++++++++----------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/src/Tgstation.Server.Host.Service/Program.cs b/src/Tgstation.Server.Host.Service/Program.cs index 2aad73d756..e34dcc7c1e 100644 --- a/src/Tgstation.Server.Host.Service/Program.cs +++ b/src/Tgstation.Server.Host.Service/Program.cs @@ -59,32 +59,29 @@ namespace Tgstation.Server.Host.Service /// public void OnExecute() { - if (Environment.UserInteractive) + if (Environment.UserInteractive && !IsAdministrator()) { - if (!IsAdministrator()) + if (!Install && !Uninstall) { - if (!(Install || Uninstall)) - { - var result = MessageBox.Show("You are running the TGS windows service executable directly. It should only be run by the service control manager. Would you like to install the service in this location?", "TGS Service", MessageBoxButtons.YesNo); - if (result == DialogResult.No) - return; - Install = true; - } - - //try to restart as admin - //its windows, first arg is .exe name guaranteed - var exe = Environment.GetCommandLineArgs().First(); - var startInfo = new ProcessStartInfo - { - UseShellExecute = true, - Verb = "runas", - Arguments = Install ? "-i" : "-u", - FileName = exe, - WorkingDirectory = Environment.CurrentDirectory, - }; - using (Process.Start(startInfo)) + var result = MessageBox.Show("You are running the TGS windows service executable directly. It should only be run by the service control manager. Would you like to install the service in this location?", "TGS Service", MessageBoxButtons.YesNo); + if (result != DialogResult.Yes) return; + Install = true; } + + //try to restart as admin + //its windows, first arg is .exe name guaranteed + var exe = Environment.GetCommandLineArgs().First(); + var startInfo = new ProcessStartInfo + { + UseShellExecute = true, + Verb = "runas", + Arguments = Install ? "-i" : "-u", + FileName = exe, + WorkingDirectory = Environment.CurrentDirectory, + }; + using (Process.Start(startInfo)) + return; } if (Install)