From e2bf78f1df4a6f1a966f410cfc1085b854af4e0e Mon Sep 17 00:00:00 2001 From: jeacott1 Date: Tue, 28 May 2019 13:25:17 +0930 Subject: [PATCH] adds a true config switch so that launching bat files on legacy machines running Interactive Services Detection don't balk. --- src/Core/ServiceWrapper/Main.cs | 3 ++- src/Core/WinSWCore/Configuration/DefaultSettings.cs | 1 + src/Core/WinSWCore/Configuration/IWinSWConfiguration.cs | 1 + src/Core/WinSWCore/ServiceDescriptor.cs | 7 +++++++ src/Core/WinSWCore/Util/ProcessHelper.cs | 4 ++-- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Core/ServiceWrapper/Main.cs b/src/Core/ServiceWrapper/Main.cs index 0197239..2046006 100644 --- a/src/Core/ServiceWrapper/Main.cs +++ b/src/Core/ServiceWrapper/Main.cs @@ -456,7 +456,8 @@ namespace winsw priority: _descriptor.Priority, callback: processCompletionCallback, logHandler: logHandler, - redirectStdin: redirectStdin); + redirectStdin: redirectStdin, + hideWindow: _descriptor.HideWindow); } public static int Main(string[] args) diff --git a/src/Core/WinSWCore/Configuration/DefaultSettings.cs b/src/Core/WinSWCore/Configuration/DefaultSettings.cs index bd74a38..9a1d924 100644 --- a/src/Core/WinSWCore/Configuration/DefaultSettings.cs +++ b/src/Core/WinSWCore/Configuration/DefaultSettings.cs @@ -18,6 +18,7 @@ namespace winsw.Configuration public string Caption { get { return null; } } public string Description { get { return null; } } public string Executable { get { return null; } } + public bool HideWindow { get { return false; } } public string ExecutablePath { diff --git a/src/Core/WinSWCore/Configuration/IWinSWConfiguration.cs b/src/Core/WinSWCore/Configuration/IWinSWConfiguration.cs index 3fb64dd..e6b6d75 100644 --- a/src/Core/WinSWCore/Configuration/IWinSWConfiguration.cs +++ b/src/Core/WinSWCore/Configuration/IWinSWConfiguration.cs @@ -14,6 +14,7 @@ namespace winsw.Configuration string Description { get; } string Executable { get; } string ExecutablePath { get; } + bool HideWindow { get; } // Installation bool AllowServiceAcountLogonRight { get; } diff --git a/src/Core/WinSWCore/ServiceDescriptor.cs b/src/Core/WinSWCore/ServiceDescriptor.cs index ea2d372..08d33c6 100755 --- a/src/Core/WinSWCore/ServiceDescriptor.cs +++ b/src/Core/WinSWCore/ServiceDescriptor.cs @@ -175,6 +175,13 @@ namespace winsw } } + public bool HideWindow + { + get { + return SingleBoolElement("hidewindow", Defaults.HideWindow); + } + } + /// /// Optionally specify a different Path to an executable to shutdown the service. /// diff --git a/src/Core/WinSWCore/Util/ProcessHelper.cs b/src/Core/WinSWCore/Util/ProcessHelper.cs index 5412ace..5de6e36 100644 --- a/src/Core/WinSWCore/Util/ProcessHelper.cs +++ b/src/Core/WinSWCore/Util/ProcessHelper.cs @@ -132,13 +132,13 @@ namespace winsw.Util /// Log handler. If enabled, logs will be redirected to the process and then reported /// Redirect standard input public static void StartProcessAndCallbackForExit(Process processToStart, String executable = null, string arguments = null, Dictionary envVars = null, - string workingDirectory = null, ProcessPriorityClass? priority = null, ProcessCompletionCallback callback = null, bool redirectStdin = true, LogHandler logHandler = null) + string workingDirectory = null, ProcessPriorityClass? priority = null, ProcessCompletionCallback callback = null, bool redirectStdin = true, LogHandler logHandler = null, bool hideWindow = false) { var ps = processToStart.StartInfo; ps.FileName = executable ?? ps.FileName; ps.Arguments = arguments ?? ps.Arguments; ps.WorkingDirectory = workingDirectory ?? ps.WorkingDirectory; - ps.CreateNoWindow = false; + ps.CreateNoWindow = hideWindow; ps.UseShellExecute = false; ps.RedirectStandardInput = redirectStdin; ps.RedirectStandardOutput = logHandler != null;