Added Windows Server detection logic

This commit is contained in:
Keivan Beigi 2017-01-03 18:56:28 -08:00
parent e0ff25d5be
commit 009dc14805
1 changed files with 36 additions and 1 deletions

View File

@ -1,14 +1,49 @@
using System;
using Microsoft.Win32;
using NLog;
using NzbDrone.Common.EnvironmentInfo;
namespace NzbDrone.Windows.EnvironmentInfo
{
public class WindowsVersionInfo : IOsVersionAdapter
{
private readonly Logger _logger;
public bool Enabled => OsInfo.IsWindows;
public WindowsVersionInfo(Logger logger)
{
_logger = logger;
}
public OsVersionModel Read()
{
return new OsVersionModel("Windows", Environment.OSVersion.Version.ToString(), Environment.OSVersion.VersionString);
var windowsServer = IsServer();
var osName = windowsServer ? "Windows Server" : "Windows";
return new OsVersionModel(osName, Environment.OSVersion.Version.ToString(), Environment.OSVersion.VersionString);
}
private bool IsServer()
{
try
{
const string subkey = @"Software\Microsoft\Windows NT\CurrentVersion";
var openSubKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey);
if (openSubKey != null)
{
var productName = openSubKey.GetValue("ProductName").ToString();
if (productName.ToLower().Contains("server"))
{
return true;
}
}
}
catch (Exception e)
{
_logger.Error(e, "Couldn't detect if running Windows Server");
}
return false;
}
}
}