Detect OS Windows 8.1

  1. 2 weeks ago

    Craig G

    Oct 6 Australia
    Edited 2 weeks ago

    I can't get my program to recognise Windows 8.1.
    I am using this code snippet from one of the posts on this forum but it recognizes for all OS except windows 8.1 which reportedly seems to show as Windows 10 for my customers.
    Unfortunately I don't have 8.1 installed anywhere to test. My experience with all things Windows 8 was unregrettably short :)

    #elseif TargetWin32
      dim OS_CODE as Integer
      os = "Windows"
      
      //try to be more specific of windows version
      Soft Declare Sub GetVersionExA Lib "Kernel32" ( info As Ptr )
      Soft Declare Sub GetVersionExW Lib "Kernel32" ( info As Ptr )
      
      Dim info As MemoryBlock
      
      If System.IsFunctionAvailable( "GetVersionExW", "Kernel32" ) Then
        info =  New MemoryBlock( 20 + (2 * 128) )
        info.Long( 0 ) = info.Size
        GetVersionExW( info )
      Else
        info =  New MemoryBlock( 148 )
        info.Long( 0 ) = info.Size
        GetVersionExA( info )
      End If
      
      Dim Str As String
      OS_CODE=info.Long(4)*100+info.long(8)
      
      Select Case OS_CODE
      Case 400  
        os = "Windows 95/NT 4.0"
      Case 410
        os = "Windows 98"
      Case 490
        os = "Windows Me"
      Case 300 To 399
        os = "Windows NT 3.51"
        OS_CODE=30
      Case 500
        os = "Windows 2000"
      Case 501
        os = "Windows XP"
      Case 502
        os = "Windows Server 2003"
      Case 600
        os = "Windows Vista"
      Case 601
        os = "Windows 7"
      Case 602
        dim s as new shell
        s.execute("ver")
        dim res as string = s.Result
        if val(mid(res,30,2)) = 10 then
          os = "Windows 10"
        else
          os = "Windows 8/8.1"
        end if
      End Select
      
      Return os
  2. Christian S

    Oct 6 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    GetVersionEx won't work unless you have manifest telling your app works with 8.1, if I remember correctly.

    Version functions in SystemInformationMBS module from us should detect it.
    See SystemInformationMBS .isWindows81 function.

  3. last week

    Craig G

    Oct 9 Australia

    Interesting, the code I posted does actually work and detects Windows 8/8.1.
    But only in the 32 bit version of the app. In the 64bit compile it doesn't work.

  4. brian f

    Oct 9 Pre-Release Testers, Xojo Pro Chilly California

    #elseif TargetWin64 ?

  5. Greg O

    Oct 9 Xojo Inc

    @brian f #elseif TargetWin64 ?

    No TargetWin32 returns True on both 32-bit and 64-bit windows.

  6. Julian S

    Oct 9 Pre-Release Testers, Xojo Pro UK
    Edited last week

    Or you could read the version details from kernel32.dll

    Here's a program that'll do that, comment line 1 and uncomment line 2 from pushbutton1.action in this example to see the version number returned from kernel32.dll

    https://www.dropbox.com/s/6v42szgbq0wzc3r/GetFileVersionInfo.xojo_binary_project?dl=1

    For example, my windows 8.1 machine returns 6.3.96000.17415

    The code was written for someone else to get the lang-codepage out of a file, it happens to work for what you want also.

    Tested on w10-64, w7-32 w8.1-32 w8.1-64 and they all seemed to work out ok.

  7. Craig G

    Oct 10 Australia

    @Julian S Or you could read the version details from kernel32.dll

    Thanks I'll try that.
    I went the long way round and installed Windows 8.1 on a virtual machine to see what was happening
    Came up with this:

        case 602 // 32bit Windows 8/8.1 and 10
          dim s as new shell
          s.execute("ver")
          dim res as string = s.Result
          if val(mid(res,30,2)) = 10 then
            os = "Windows 10"
          else
            os = "Windows 8/8.1"
          end if
        case 603 // 64 bit Windows 8.1
          os = "Windows 8.1"
        case 1000 // 64 bit Windows 10
          os = "Windows 10"
        case else
          os = "Unknown Windows build - " + str(OS_CODE)
        End Select

    Unfortunately couldn't test 64bit Windows 8

or Sign Up to reply!