Detecting Windows 10 Version

Detecting Windows 10 version

The most straight-forward way to retrieve the true OS version is to call RtlGetVersion. It is what GetVersionEx and VerifyVersionInfo call, but doesn't employ the compatibility shims.

You can either use the DDK (by #including <ntddk.h> and linking against NtosKrnl.lib from kernel mode, or ntdll.lib from user mode), or use runtime dynamic linking as in the following snippet:

typedef LONG NTSTATUS, *PNTSTATUS;
#define STATUS_SUCCESS (0x00000000)

typedef NTSTATUS (WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);

RTL_OSVERSIONINFOW GetRealOSVersion() {
HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
if (hMod) {
RtlGetVersionPtr fxPtr = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion");
if (fxPtr != nullptr) {
RTL_OSVERSIONINFOW rovi = { 0 };
rovi.dwOSVersionInfoSize = sizeof(rovi);
if ( STATUS_SUCCESS == fxPtr(&rovi) ) {
return rovi;
}
}
}
RTL_OSVERSIONINFOW rovi = { 0 };
return rovi;
}

In case you need additional information you can pass an RTL_OSVERSIONINFOEXW structure in place of the RTL_OSVERSIONINFOW structure (properly assigning the dwOSVersionInfoSize member).

This returns the expected result on Windows 10, even when there is no manifest attached.


As an aside, it is commonly accepted as a better solution to provide different implementations based on available features rather than OS versions.

In NSIS , how to detect Windows version for Win 10 and Windows 19

Use WinVer.nsh

!include WinVer.nsh

Function .onInit
${IfNot} ${AtLeastWin10}
MessageBox mb_iconStop "Windows 10 blah blah"
Abort
${EndIf}
FunctionEnd

Asking for plain Windows 10 but a specific server version is rather strange but if you must:

${If} ${IsServerOS}
${AndIf} ${AtLeastWaaS} 1809
...
${EndIf}

Is there an *official* way to detect Windows 11?

The question thread "Windows 11 build ver is still 10.0.22000.194" on Microsoft Q&A has received responses from two Microsoft employees. In the accepted answer, one says:

At least for now, OS build number 22000 is the standard that distinguishes Windows 10 from Windows 11.

And, in a comment below the answer, another adds:

This is correct. Anything above 10.0.22000.0 is Win 11. Anything below is Win 10.

This suggests that, at the time of that writing, a week after the public release of Windows 11, Microsoft had not yet published an official recommendation for software developers. That may obviously change at some point, but until then the 22000 build number seems to be the criterion one should rely on to draw the line between Windows 10 and 11.

Get current version OS in Windows 10 in C#

Add application manifest to your application and add the supportedOS Id of Windows 8.1 and Windows 10 to the manifest:

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
</application>
</compatibility>

Now Environment.OSVersion includes the correct data for Windows 8.1 and Windows 10 and not 6.2 to indicate you run Windows 8. This is a change since Windows 8.1.

Reliable way to get Windows Version from registry

Instead of reading the value CurrentVersion, read the new values CurrentMajorVersionNumber (which is 10) and CurrentMinorVersionNumber (which is 0) under Windows 10. Those 2 keys are new in Windows 10 to detect Windows Version from Registry.

Detecting Windows 10 OS Build minor version

This UBR value is stored in Registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion in a DWORD which you can query

Sample Image

How to get Windows Version - as in Windows 10, version 1607?

according to MSDN official link there's a specific version number for each windows version out there. in dot net this can be read using the Environment.OSVersion object.

Console.WriteLine("OSVersion: {0}", Environment.OSVersion);
//output: OSVersion: Microsoft Windows NT 6.2.9200.0

What you are looking for is called ReleaseID not a version of windows.
this be can read from registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ReleaseId

using Microsoft.Win32;

string releaseId = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ReleaseId", "").ToString();
Console.WriteLine(releaseId);


Related Topics



Leave a reply



Submit