diff --git a/src/Tgstation.Server.Host.Service/Program.cs b/src/Tgstation.Server.Host.Service/Program.cs index 9056e67f70..673accd9a0 100644 --- a/src/Tgstation.Server.Host.Service/Program.cs +++ b/src/Tgstation.Server.Host.Service/Program.cs @@ -118,6 +118,32 @@ namespace Tgstation.Server.Host.Service { if (Uninstall) return; // oh no, it's retarded... + + // First check if the service already exists + if (Environment.UserInteractive) + foreach (ServiceController sc in ServiceController.GetServices()) + if (sc.ServiceName == "tgstation-server" || sc.ServiceName == "tgstation-server-4") + { + DialogResult result = MessageBox.Show($"You already have another TGS service installed ({sc.ServiceName}). Would you like to uninstall it now? Pressing \"No\" will cancel this install.", "TGS Service", MessageBoxButtons.YesNo); + if (result != DialogResult.Yes) + return; // is this needed after exit? + + // Stop it first to give it some cleanup time + if (sc.Status == ServiceControllerStatus.Running) + { + sc.Stop(); + sc.WaitForStatus(ServiceControllerStatus.Stopped); + } + + // And remove it + using (ServiceInstaller si = new ServiceInstaller()) + { + si.Context = new InstallContext($"old-{sc.ServiceName}-uninstall.log", null); + si.ServiceName = sc.ServiceName; + si.Uninstall(null); + } + } + using (var processInstaller = new ServiceProcessInstaller()) using (var installer = new ServiceInstaller()) {