Improved compatibility with systems supporting interactive services (e.g. Win7)

master v0.1.3
Inga 🏳‍🌈 4 years ago
parent c9e4e089c8
commit 20d7d33023
  1. 23
      RadeonResetBugFixService/ConsoleHelper.cs
  2. 9
      RadeonResetBugFixService/Program.cs
  3. 1
      RadeonResetBugFixService/RadeonResetBugFixService.csproj

@ -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());
}
}
}

@ -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())
{

@ -58,6 +58,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConsoleHelper.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Contracts\DeviceInfo.cs" />
<Compile Include="Contracts\DevicesStatus.cs" />

Loading…
Cancel
Save