From 6a1228678390f2ed9fc178e9fda3749dea42df77 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 11 Oct 2022 21:21:06 +0200 Subject: [PATCH] Windows - Fixed PowerShell error on Windows shutdown --- src/Artemis.UI.Windows/ApplicationStateManager.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Artemis.UI.Windows/ApplicationStateManager.cs b/src/Artemis.UI.Windows/ApplicationStateManager.cs index c08f42316..1630c95ef 100644 --- a/src/Artemis.UI.Windows/ApplicationStateManager.cs +++ b/src/Artemis.UI.Windows/ApplicationStateManager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -16,6 +16,8 @@ namespace Artemis.UI.Windows; public class ApplicationStateManager { + private const int SM_SHUTTINGDOWN = 0x2000; + public ApplicationStateManager(IKernel kernel, string[] startupArguments) { StartupArguments = startupArguments; @@ -100,7 +102,8 @@ public class ApplicationStateManager private void RunForcedShutdownIfEnabled() { - if (StartupArguments.Contains("--disable-forced-shutdown")) + // Don't run a forced shutdown if Windows itself is shutting down, the new PowerShell process will fail + if (GetSystemMetrics(SM_SHUTTINGDOWN) != 0 || StartupArguments.Contains("--disable-forced-shutdown")) return; ProcessStartInfo info = new() @@ -112,4 +115,7 @@ public class ApplicationStateManager }; Process.Start(info); } + + [System.Runtime.InteropServices.DllImport("user32.dll")] + private static extern int GetSystemMetrics(int nIndex); } \ No newline at end of file