-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OS version check without requiring app.manifest
- Loading branch information
Showing
2 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace ModernWpf | ||
{ | ||
internal static class OSVersionHelper | ||
{ | ||
internal static bool IsWindowsNT { get; } = Environment.OSVersion.Platform == PlatformID.Win32NT; | ||
|
||
internal static bool IsWindows10 { get; } = IsWindowsNT && IsWindows10Impl(); | ||
|
||
private static bool IsWindows10Impl() | ||
{ | ||
var osv = new RTL_OSVERSIONINFOEX(); | ||
osv.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osv); | ||
int ret = RtlGetVersion(out osv); | ||
return ret == 0 && osv.dwMajorVersion >= 10; | ||
} | ||
|
||
[DllImport("ntdll.dll")] | ||
private static extern int RtlGetVersion(out RTL_OSVERSIONINFOEX lpVersionInformation); | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
private struct RTL_OSVERSIONINFOEX | ||
{ | ||
internal uint dwOSVersionInfoSize; | ||
internal uint dwMajorVersion; | ||
internal uint dwMinorVersion; | ||
internal uint dwBuildNumber; | ||
internal uint dwPlatformId; | ||
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] | ||
internal string szCSDVersion; | ||
} | ||
} | ||
} |