How to determine OS, which version, and which ver of windoz?

[quote=136115:@Oliver Osswald]Dave’s code does not return a correct result on Yosemite.

I would expect sver to be 1010 but it is 1090.

How can I determine in code that my app is running on yosemite?[/quote]

See Norman’s method in this recent discussion

Theres another discussion about this and dave corrected his code in that

@ Michel and Norman: Thanks a lot for the links!

Well it works properly on my Yosemite machine… 10.9.0 would be Maverick

fragmented topics… see Normans post above

Hi Forum,

I use Dave’s code in order to detect the currently used OS. (By the many: many thanks!!!)

Unfortunately, it gives incorrect result for Windows 10.
I get a 602 which indicates Windows 8. Also Christian’s SysteminformationMBS.WinMajorVersion returns a “6”.

Any ideas?

My code wasn’t even updated for Win8 either… someone would have to experiment to determine what the correct values are to detect Win8 and Win10

For whatever reason, Windows 10 shows as 602, build 9200. Which means it is not possible to distinguish 8, 8.1 and 10 by your method.

The best I found is to shell to Ver, which value is for Windows 10.

Microsoft Windows [Version 10.0.10240]

First number is 10, obviously, and the last digits are the build.

So basically something like this would do :

[code]Function WhichSystem() As String
Dim noerror As Boolean
Dim result As Integer
Dim sver As String
Dim sversion As String
Dim os As String
#If TargetMacOS
If noerror Then
sversion=sver.Left(2) + “.” + sver.Mid(3,1) + “.” + sver.Right(1)
Select Case OS_CODE

  Case 0
  Case 1
  Case 2
  Case 3
  Case 4
  Case 5
  Case 6
    os="Snow Leopard"
  Case 7
  Case 8
    os="Mountain Lion"
  Case Else
  End Select
  Return "Mac OSX "+os+" "+sversion
  Return ""
End If

#ElseIf TargetWin32

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 )
  info =  New MemoryBlock( 148 )
  info.Long( 0 ) = info.Size
  GetVersionExA( info )
End If

Dim Str As String
Dim OS_CODE as Integer
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"
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
  dim res as string = s.Result
  if val(mid(res,30,2)) = 10 then
    os = "Windows 10"
    dim build as double = val(mid(res,33,10))*100000
    Str = " Build "+format(build,"00000")
    os = "Windows 8/8.1"
  end if
End Select
if Str = "" then Str = " Build " + Str( info.Long( 12 ) )

If System.IsFunctionAvailable( "GetVersionExW", "Kernel32" ) Then
  Str = Str + " " + Trim( info.WString( 20 ) )
  Str = Str + " " + Trim( info.CString( 20 ) )
End If

os = os + Str
Return os

End Function

I tested it with Windows 10 and Windows 8.1. Since Windows 8 and 8.1 have exactly the same results with Dave method and Ver, I do not know how to discriminate them.

Please look at the “Community Additions” at the end of the document.

Edit -> added:

It appears the same kind of conundrum happens with Mavericks, Yosemite and El Capitan on the Mac side. All report OS_CODE = 9.

The best I found was to use a shell to sw_vers -productVersion which gives the number, for instance here with El Capitan 10.11.

A similar structure as what happens for 602 in Windows can be used.

So, Win and Mac OS are not so different?

[quote=203751:@Maurizio Rossi]

Please look at the “Community Additions” at the end of the document.

Edit -> added:[/quote]

I just checked, that method is used in OSVersionInformationWFS.

As it seems from what you point to, though, the same problem presents to distinguish 8 and 8.1.

They are often more similar than what some may think :wink:

They are both products of human beings…

I fixed it here already.

Which plugin is it ? Are you able to distinguish between 8 and 8.1 ?

Yes. I’ll upload new plugins tomorrow and than you can check it.
Should detect 7, 8, 8.1 and 10 correctly.

And it’s really a problem that Microsoft’s functions don’t return the right OS version.

GetVersionExW and GetVersionExA it seems were both deprecated in Win8.1 and don’t return codes beyond Win7 anymore.
They replaced it with a boatload of “Version Helper” API code, that I’m not sure how (or if) they can be declared in XOJO

If you are tempted to muck around with the EXE’s Manifest, see my warnings here:

15.2pr9 is online, so everyone using MBS Plugin should now see version 10 being reported correctly.