1

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):

  1. to get the semi-annual tag string representation (such as 21H1 or 2004):
    • if available: read the DisplayVersion
    • otherwise: read the ReleaseId
  1. to get the version number:

--

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.

paulgutten
  • 293
  • 3
  • 11
  • Does [`Environment.OSVersion`](https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem?view=net-5.0) work for you? – devsmn Nov 08 '21 at 14:30
  • 2
    Seems like [they actually fixed](https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/5.0/environment-osversion-returns-correct-version) the manifest problem - starting from .NET 5, apparently. That might be the future proof-version.. in the future. – devsmn Nov 08 '21 at 14:40

0 Answers0