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 was forced to read the ReleaseId.
  • but recently, microsoft switched over to DisplayVersion.

--

microsoft seems to keep changing their OS detail fingerprint locations all the time.
making it even harder by introducing things like the "version lie".

is there any simple and reliable way to log the key information, such as:

Name: Windows 10 Enterprise
Service Pack: Release 2009 (21H1)
Build Number: 10.0.19043

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
  • 273
  • 3
  • 10
  • Does [`Environment.OSVersion`](https://docs.microsoft.com/en-us/dotnet/api/system.operatingsystem?view=net-5.0) work for you? – imsmn Nov 08 '21 at 14:30
  • 2
    Seems like [they actually fixed](https://docs.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. – imsmn Nov 08 '21 at 14:40

0 Answers0