1
0

Fixes on incorrect version detections

This commit is contained in:
Benjamin Höglinger-Stelzer 2018-10-24 22:02:36 +02:00
parent a251a9ee5a
commit bb7d53110f
3 changed files with 141 additions and 102 deletions

View File

@ -8,11 +8,10 @@
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
mc:Ignorable="d"
Title="Derping Drivers - Windows driver compatibility detection tool"
Height="400" Width="700"
Height="440" Width="700"
ShowMaxRestoreButton="False"
ResizeMode="NoResize"
WindowStartupLocation="CenterScreen"
SaveWindowPosition="True"
BorderThickness="0"
GlowBrush="{DynamicResource AccentColorBrush}"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
@ -28,6 +27,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
@ -40,29 +40,33 @@
<Label Grid.Row="0" Grid.Column="0">Windows version name:</Label>
<Label Grid.Row="0" Grid.Column="2" Content="{Binding Path=OsVersionName}"
ToolTip="Product name of the operating system." />
<Label Grid.Row="1" Grid.Column="0">Windows edition name:</Label>
<Label Grid.Row="1" Grid.Column="2" Content="{Binding Path=OsEditionName}"
ToolTip="Edition name of the operating system (if any)." />
<Label Grid.Row="1" Grid.Column="0">Windows version number:</Label>
<Label Grid.Row="1" Grid.Column="2" Content="{Binding Path=OsVersion}"
<Label Grid.Row="2" Grid.Column="0">Windows version number:</Label>
<Label Grid.Row="2" Grid.Column="2" Content="{Binding Path=OsVersion}"
ToolTip="Detailed build number of the operating system." />
<Label Grid.Row="2" Grid.Column="0">Windows architecture:</Label>
<Label Grid.Row="2" Grid.Column="2" Content="{Binding Path=OsArchitecture}"
<Label Grid.Row="3" Grid.Column="0">Windows architecture:</Label>
<Label Grid.Row="3" Grid.Column="2" Content="{Binding Path=OsArchitecture}"
ToolTip="The architecture of the operating system. A 32-bit driver can't get loaded on a 64-bit system and vice versa." />
<Label Grid.Row="3" Grid.Column="0">Current boot mode:</Label>
<Label Grid.Row="3" Grid.Column="2" Content="{Binding Path=BootMode}"
<Label Grid.Row="4" Grid.Column="0">Current boot mode:</Label>
<Label Grid.Row="4" Grid.Column="2" Content="{Binding Path=BootMode}"
ToolTip="The current boot mode. Either UEFI (modern) or Legacy BIOS (old)." />
<Label Grid.Row="4" Grid.Column="0">Secure Boot state:</Label>
<Label Grid.Row="4" Grid.Column="2" Content="{Binding Path=SecureBootEnabled}"
<Label Grid.Row="5" Grid.Column="0">Secure Boot state:</Label>
<Label Grid.Row="5" Grid.Column="2" Content="{Binding Path=SecureBootEnabled}"
ToolTip="Enforces stricter cryptographic driver signatures." />
<Label Grid.Row="5" Grid.Column="0">OS upgrade status:</Label>
<Label Grid.Row="5" Grid.Column="2" Content="{Binding Path=OsUpgradeStatus}"
<Label Grid.Row="6" Grid.Column="0">OS upgrade status:</Label>
<Label Grid.Row="6" Grid.Column="2" Content="{Binding Path=OsUpgradeStatus}"
ToolTip="Determines if the system has been in-place upgraded from an older version of Windows." />
<Label Grid.Row="6" Grid.Column="0">Test Signing state:</Label>
<Label Grid.Row="6" Grid.Column="2" Content="{Binding Path=TestSigningStatus}"
<Label Grid.Row="7" Grid.Column="0">Test Signing state:</Label>
<Label Grid.Row="7" Grid.Column="2" Content="{Binding Path=TestSigningStatus}"
ToolTip="Allows loading of test/self-signed drivers if enabled." />
</Grid>

View File

@ -33,7 +33,12 @@ namespace DerpingDrivers
/// <summary>
/// Gets Operating System display name.
/// </summary>
public string OsVersionName => $"{OsVersionInfo.Name} {OsVersionInfo.Edition}";
public string OsVersionName => OsVersionInfo.Name;
/// <summary>
/// Gets Operating System edition name.
/// </summary>
public string OsEditionName => string.IsNullOrEmpty(OsVersionInfo.Edition) ? "None" : OsVersionInfo.Edition;
/// <summary>
/// Gets Operating System build number.

View File

@ -1,6 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
using Markdig.Helpers;
using Microsoft.Win32;
// http://www.codeproject.com/Articles/73000/Getting-Operating-System-Version-Info-Even-for-Win
@ -18,6 +22,16 @@ namespace DerpingDrivers.Util
/// </summary>
public static class OsVersionInfo
{
private static readonly List<string> Windows10ReleaseIds = new OrderedList<string>
{
"1507",
"1607",
"1703",
"1709",
"1803",
"1809"
};
#region SERVICE PACK
/// <summary>
@ -39,14 +53,15 @@ namespace DerpingDrivers.Util
#endregion SERVICE PACK
#region Windows 10 Detection
#region Windows 10/Server 2016+ Detection
private static bool IsWindows10()
{
var productName = RegistryRead(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion",
"ProductName", "");
if (productName.StartsWith("Windows 10", StringComparison.OrdinalIgnoreCase)) return true;
return false;
var releaseId = (string) Registry.GetValue(
@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion",
"ReleaseId", null);
return !string.IsNullOrEmpty(releaseId) && Windows10ReleaseIds.Any(id => id.Contains(releaseId));
}
#endregion
@ -244,8 +259,7 @@ namespace DerpingDrivers.Util
var edition = string.Empty;
var osVersion = Environment.OSVersion;
var osVersionInfo = new OSVERSIONINFOEX();
osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
var osVersionInfo = new OSVERSIONINFOEX {dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX))};
if (GetVersionEx(ref osVersionInfo))
{
@ -556,6 +570,10 @@ namespace DerpingDrivers.Util
private static string _name;
private static string ReleaseId => (string) Registry.GetValue(
@"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion",
"ReleaseId", null);
/// <summary>
/// Gets the name of the operating system running on this computer.
/// </summary>
@ -673,76 +691,11 @@ namespace DerpingDrivers.Util
break;
case 6:
switch (minorVersion)
{
case 0:
switch (productType)
{
case 1:
name = "Windows Vista";
break;
case 3:
name = "Windows Server 2008";
break;
}
break;
case 1:
switch (productType)
{
case 1:
name = "Windows 7";
break;
case 3:
name = "Windows Server 2008 R2";
break;
}
break;
case 2:
switch (productType)
{
case 1:
name = "Windows 8";
break;
case 3:
name = "Windows Server 2012";
break;
}
break;
case 3:
switch (productType)
{
case 1:
name = "Windows 8.1";
break;
case 3:
name = "Windows Server 2012 R2";
break;
}
break;
}
name = ParseVistaThrough8(minorVersion, productType);
break;
case 10:
switch (minorVersion)
{
case 0:
switch (productType)
{
case 1:
name = "Windows 10";
break;
case 3:
name = "Windows Server 2016";
break;
}
break;
}
name = ParseWindows10Version(minorVersion, productType, ReleaseId);
break;
}
@ -757,6 +710,83 @@ namespace DerpingDrivers.Util
}
}
private static string ParseVistaThrough8(int minorVersion, byte productType)
{
switch (minorVersion)
{
case 0:
switch (productType)
{
case 1:
return "Windows Vista";
case 3:
return "Windows Server 2008";
}
break;
case 1:
switch (productType)
{
case 1:
return "Windows 7";
case 3:
return "Windows Server 2008 R2";
}
break;
case 2:
switch (productType)
{
case 1:
return "Windows 8";
case 3:
return "Windows Server 2012";
}
break;
case 3:
switch (productType)
{
case 1:
return "Windows 8.1";
case 3:
return "Windows Server 2012 R2";
}
break;
}
return string.Empty;
}
private static string ParseWindows10Version(int minorVersion, byte productType, string releaseId)
{
switch (minorVersion)
{
case 0:
switch (productType)
{
case 1:
return "Windows 10";
case 3:
switch (releaseId)
{
case "1607":
return "Windows Server 2016";
case "1809":
return "Windows Server 2019";
}
break;
}
break;
}
return string.Empty;
}
#endregion NAME
#region PINVOKE
@ -829,16 +859,16 @@ namespace DerpingDrivers.Util
[StructLayout(LayoutKind.Sequential)]
private struct SYSTEM_INFO
{
internal _PROCESSOR_INFO_UNION uProcessorInfo;
public uint dwPageSize;
public IntPtr lpMinimumApplicationAddress;
public IntPtr lpMaximumApplicationAddress;
public IntPtr dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public uint dwProcessorType;
public uint dwAllocationGranularity;
public ushort dwProcessorLevel;
public ushort dwProcessorRevision;
internal readonly _PROCESSOR_INFO_UNION uProcessorInfo;
public readonly uint dwPageSize;
public readonly IntPtr lpMinimumApplicationAddress;
public readonly IntPtr lpMaximumApplicationAddress;
public readonly IntPtr dwActiveProcessorMask;
public readonly uint dwNumberOfProcessors;
public readonly uint dwProcessorType;
public readonly uint dwAllocationGranularity;
public readonly ushort dwProcessorLevel;
public readonly ushort dwProcessorRevision;
}
#endregion SYSTEM_INFO
@ -848,9 +878,9 @@ namespace DerpingDrivers.Util
[StructLayout(LayoutKind.Explicit)]
private struct _PROCESSOR_INFO_UNION
{
[FieldOffset(0)] internal uint dwOemId;
[FieldOffset(0)] internal ushort wProcessorArchitecture;
[FieldOffset(2)] internal ushort wReserved;
[FieldOffset(0)] internal readonly uint dwOemId;
[FieldOffset(0)] internal readonly ushort wProcessorArchitecture;
[FieldOffset(2)] internal readonly ushort wReserved;
}
#endregion _PROCESSOR_INFO_UNION