in the log file of my application (c# / .net 4.8) i'm writing out the details of the OS name, variant / edition, version number, build number.
in the case of support tickets this is quite handy to quickly understand on what environment the application was running on.
over the years i have been forced to tweak my detection algorithm multiple times.
- first, i'm reading the
ProductName
at "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion". - for windows 7 i had added logic to also read the
CSDVersion
- to check the service pack level. - i also want to log the "build number". but starting with windows 8 (?) microsoft introduced the "version lie". to get around this the solution was to p/invoke
RtlGetVersion
(from ntdll). - for more details on the exact version number i'm also doing some manual parsing of
BuildLabEx
. - for windows 10 i added reading of the
ReleaseId
(such as 1903 / 2004 / 2009). - but recently, microsoft switched over to
DisplayVersion
(such as 21H1 / 21H2).
microsoft seems to keep changing their OS detail fingerprint locations all the time ...
--
this is my current approach (october 2022):
- to get the semi-annual tag string representation (such as 21H1 or 2004):
- if available: read the
DisplayVersion
- otherwise: read the
ReleaseId
- if available: read the
- to get the version number:
- call
RtlGetVersion
to get "major", "minor", "build" - if available: read the
UBR
from the registry to also get the "revision" (https://serverfault.com/a/892702/228245)
- call
--
question:
is there any simple and reliable way to log the key information, such as:
Name: Windows 10 Enterprise
Version: 21H1
Build Number: 10.0.19043.985
the solution should also work in the "future" ;)
--
a note to the comments:
System.Environment.OSVersion
does not work, because this requires updated manifest entries. see: System.Environment.OSVersion returns wrong version
that's another variant of the "version lie" that i have mentioned.