[SOLVED] Problem detecting kernel version

Discussion in 'Mixed Languages' started by QuantumBug, May 30, 2015.

  1. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,293
    60
    #1 QuantumBug, May 30, 2015
    Last edited by a moderator: Apr 20, 2017
    I'm running Windows 8.1 and this code returns a build version of 6.2.9600 when it should be 6.3.9600...

    Code:
    Console.WriteLine("Current OS: {0}", Environment.OSVersion.VersionString)
    This isn't logical to me. It is returning at incorrect kernel version.

    win32_operatingsystem * version returns the correct version of 6.3.9600.

    Can anyone explain? It returns the same regardless of whether I'm running in the hosting process or running independently.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Michaela Joy

    Michaela Joy MDL Crazy Lady

    Jul 26, 2012
    3,438
    3,578
    120
    @Dev:
    Maybe assign "Environment.OSVersion.VersionString" to a string variable and then write the string to the console?

    Just a guess :eek::

    :MJ
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,801
    44,858
    150
    Windows lies to you on purpose for "compatibility".

    Instead of having to add GUIDs that mark compatibility, then you need a new one (recompile), next OS, I found a quick solution.

    I just get the File Version Info of Kernel32.dll. First part is Major Version, Second is Minor version, you can determine it there.

    Before I did this MTK believed Windows 10 TP to be Windows 8.1 because the API consciously lies to you about what OS you are on, which is a terrible practice to combat terrible version checking code, instead of giving us a solid API/method.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Tito

    Tito Super Mod / Adviser
    Staff Member

    Nov 30, 2009
    17,215
    14,777
    340
    @CODYQX4

    Exactly! I've seen (& reported) no of applications detecting 8.1 as 6.2.

    o_O
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,293
    60
    #5 QuantumBug, May 30, 2015
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Issue sorted: I forgot to edit the application manifest (windows settings)

    If you don't point your application at Windows 8.1 it will run pointed at Windows 8. The following code will open compatibility back to Vista.

    Code:
      <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">    <application>
          <!-- A list of all Windows versions that this application is designed to work with. 
          Windows will automatically select the most compatible environment.-->
    
    
          <!-- If your application is designed to work with Windows Vista, uncomment the following supportedOS node-->
          <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>
    
    
          <!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
          <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
    
    
          <!-- If your application is designed to work with Windows 8, uncomment the following supportedOS node-->
          <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>
    
    
          <!-- If your application is designed to work with Windows 8.1, uncomment the following supportedOS node-->
          <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
    
    
        </application>
      </compatibility>
    Okay thanks CODY, I wrote the following to help others having this issue. Maybe there is a better way, but it works for me. My problem was detecting if the Operating System is not Windows 8 or higher.

    Dimension a global string, this way we can read it anywhere

    Code:
    Public strver As String = Nothing
    Process to get file version of kernel32

    Code:
        Dim fv As FileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\kernel32.dll")
            Dim strver As String = fv.ProductMajorPart & "." & fv.ProductMinorPart
    Above code thanks to Alphawaves

    Usage...

    Code:
            If strver Is Nothing Then
                'Do what you want
            Else
                If strver < "6.2" Then
                    MessageBox.Show("Windows 8 or later required.")
                Else
                    'Do compatible code
                End If
            End If
    For those who want to identify versions look here and here

    Regards, The Dev.

    I'm pretty sure this could be the issue?

    "* For applications that have been manifested for Windows 8.1 or Windows 10 Insider Preview. Applications not manifested for Windows 8.1 or Windows 10 Insider Preview will return the Windows 8 OS version value (6.2). To manifest your applications for Windows 8.1 or Windows 10 Insider Preview, refer to Targeting your application for Windows."

    -Citation from
    https://msdn.microsoft.com/en-gb/library/windows/desktop/ms724832(v=vs.85).aspx
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. CODYQX4

    CODYQX4 MDL Developer

    Sep 4, 2009
    4,801
    44,858
    150
    #6 CODYQX4, May 30, 2015
    Last edited by a moderator: Apr 20, 2017
    Those are the GUID in question.

    But you are forced to add a new one every time a new OS comes out.

    What about the case of MTK, where lying about the OS version means the whole system might get bricked? Driver installlers that cause perma-BSOD?

    I did this for 8 and I did it for 8.1, but I got away from it because it makes all old releases still broken.

    PS: Don't assume you only need 3 characters. Your code will fail if either major or minor version are longer than 1 digit.

    As of this moment, you'll get version "10." if you run on Windows 10.

    The File Version API lets you get the Major and Minor parts however they may be. You can form those as Major + "." + Minor and cast that string into a decimal for checking.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,293
    60
    Thanks CODY. I will update the code tomorrow.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,864
    20,049
    180
    #8 Alphawaves, May 31, 2015
    Last edited by a moderator: Apr 20, 2017
    How about something like:
    Code:
     FileVersionInfo fv = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + @"\kernel32.dll");
                string version = fv.ProductMajorPart + "." + fv.ProductMinorPart;
    :eek:

    EDIT:
    oops forgot your VB guy:
    Code:
    Dim fv As FileVersionInfo = FileVersionInfo.GetVersionInfo(Environment.SystemDirectory + "\kernel32.dll")
            Dim version As String = fv.ProductMajorPart & "." & fv.ProductMinorPart
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,473
    1,293
    60
    #9 QuantumBug, May 31, 2015
    Last edited by a moderator: Apr 20, 2017
    (OP)
    No Alpha, VB and C# now :)

    Learning... slowly. Thanks for the code, I still have a habit of rushing.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...