diff --git a/RadeonResetBugFixService/ConsoleHelper.cs b/RadeonResetBugFixService/ConsoleHelper.cs new file mode 100644 index 0000000..c9010a8 --- /dev/null +++ b/RadeonResetBugFixService/ConsoleHelper.cs @@ -0,0 +1,23 @@ +namespace RadeonResetBugFixService +{ + using System; + using System.Runtime.InteropServices; + + static class ConsoleHelper + { + private static class NativeMethods + { + [DllImport("kernel32.dll")] + public static extern IntPtr GetConsoleWindow(); + + [DllImport("user32.dll")] + public static extern bool IsWindowVisible(IntPtr hWnd); + } + + // Code taken from https://stackoverflow.com/a/53716169 + public static bool HaveVisibleConsole() + { + return NativeMethods.IsWindowVisible(NativeMethods.GetConsoleWindow()); + } + } +} diff --git a/RadeonResetBugFixService/Program.cs b/RadeonResetBugFixService/Program.cs index 60ef90a..79f6adb 100644 --- a/RadeonResetBugFixService/Program.cs +++ b/RadeonResetBugFixService/Program.cs @@ -1,6 +1,7 @@ namespace RadeonResetBugFixService { using System; + using System.Runtime.InteropServices; using System.Security.Principal; using System.ServiceProcess; using ThirdParty.ServiceHelpers; @@ -17,7 +18,13 @@ throw new ArgumentNullException(nameof(args)); } - if (Environment.UserInteractive) + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + Console.Error.WriteLine("This program only runs on Windows"); + return -1; + } + + if (ConsoleHelper.HaveVisibleConsole()) { if (!HasAdministratorPrivileges()) { diff --git a/RadeonResetBugFixService/RadeonResetBugFixService.csproj b/RadeonResetBugFixService/RadeonResetBugFixService.csproj index 8b48649..40855ee 100644 --- a/RadeonResetBugFixService/RadeonResetBugFixService.csproj +++ b/RadeonResetBugFixService/RadeonResetBugFixService.csproj @@ -58,6 +58,7 @@ +