From c647157757b23009ca7866f3710465e93a7f0ab3 Mon Sep 17 00:00:00 2001 From: Christian Seidlitz Date: Sat, 17 Nov 2018 20:42:38 +0100 Subject: [PATCH] using dotnet 4.0 client fw, 60s timeout kill using different framework, so no config file is required to start with correct framework --- App.config | 8 ++++---- Program.cs | 27 +++++++++++++++++---------- RunHiddenConsole.csproj | 3 ++- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/App.config b/App.config index d740e88..95a79d2 100644 --- a/App.config +++ b/App.config @@ -1,6 +1,6 @@ - + - - - \ No newline at end of file + + + diff --git a/Program.cs b/Program.cs index 294262d..22a7fbc 100644 --- a/Program.cs +++ b/Program.cs @@ -1,7 +1,6 @@ namespace PowerShellWindowHost { using System; - using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Reflection; @@ -14,10 +13,15 @@ public static int Main(string[] args) var executingAssembly = Assembly.GetExecutingAssembly(); var fullName = Path.GetFileName(executingAssembly.Location); - + + SimpleLog.Prefix = $"{fullName}."; + + SimpleLog.Info($"RunHiddenConsole Executing Assembly FullName: {fullName}"); + var match = Regex.Match(fullName, @"(.+)w(\.\w{1,3})"); if (!match.Success) { + SimpleLog.Error("Unable to find target executable name in own executable name."); return -7001; } @@ -28,8 +32,8 @@ public static int Main(string[] args) var startInfo = new ProcessStartInfo { - CreateNoWindow = true, - UseShellExecute = false, + ////CreateNoWindow = true, + ////UseShellExecute = false, WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = Directory.GetCurrentDirectory(), Arguments = string.Join(" ", args), @@ -41,20 +45,23 @@ public static int Main(string[] args) var proc = Process.Start(startInfo); if (proc == null) { + SimpleLog.Error("Unable to start the target process."); return -7002; } - proc.WaitForExit(); + if (!proc.WaitForExit(60000)) + { + SimpleLog.Error("Process didn't close within 60s. Killing."); + proc.Kill(); + } + return proc.ExitCode; } - catch (Win32Exception) + catch (Exception ex) { + SimpleLog.Error("Starting target process threw an unknown Exception: " + ex); return -7003; } - catch (SystemException) - { - return -7004; - } } } } diff --git a/RunHiddenConsole.csproj b/RunHiddenConsole.csproj index 83efc71..0f26dff 100644 --- a/RunHiddenConsole.csproj +++ b/RunHiddenConsole.csproj @@ -8,10 +8,11 @@ WinExe PowerShellWindowHost hiddenw - v4.5.2 + v4.0 512 true true + Client PowerShellWindowHost.Program