.
, . , Google, , .
, , .
, . , . , Microsoft . .
, .
After looking at the parameters, I found several links (surprisingly few compared to the application manifest) that instead suggested using a registry search.
Check out this diagram from MS regarding comparison with OS releases: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832.aspx
My class is (chopped off) ComputerInfowith properties WinMajorVersion, WinMinorVersionand IsServerlooks like this:
using Microsoft.Win32;
namespace Inspection
{
public static class ComputerInfo
{
public static uint WinMajorVersion
{
get
{
dynamic major;
if (TryGeRegistryKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentMajorVersionNumber", out major))
{
return (uint) major;
}
dynamic version;
if (!TryGeRegistryKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", out version))
return 0;
var versionParts = ((string) version).Split('.');
if (versionParts.Length != 2) return 0;
uint majorAsUInt;
return uint.TryParse(versionParts[0], out majorAsUInt) ? majorAsUInt : 0;
}
}
public static uint WinMinorVersion
{
get
{
dynamic minor;
if (TryGeRegistryKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentMinorVersionNumber",
out minor))
{
return (uint) minor;
}
dynamic version;
if (!TryGeRegistryKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentVersion", out version))
return 0;
var versionParts = ((string) version).Split('.');
if (versionParts.Length != 2) return 0;
uint minorAsUInt;
return uint.TryParse(versionParts[1], out minorAsUInt) ? minorAsUInt : 0;
}
}
public static uint IsServer
{
get
{
dynamic installationType;
if (TryGeRegistryKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "InstallationType",
out installationType))
{
return (uint) (installationType.Equals("Client") ? 0 : 1);
}
return 0;
}
}
private static bool TryGeRegistryKey(string path, string key, out dynamic value)
{
value = null;
try
{
var rk = Registry.LocalMachine.OpenSubKey(path);
if (rk == null) return false;
value = rk.GetValue(key);
return value != null;
}
catch
{
return false;
}
}
}
}
source
share