Can anyone tell me how to programatically know what version of what OS is being used? I will need to know the answer for all OS’, but right now, I am focused on knowing what version of Windoz is currently running - XP, Vista, 7, 8 etc.
Can’t help with Windows, but on the Mac there are a couple of ways. The most common is to use gestalts, but if you use the System Profiler, you can also get the build number of the OS.
Function getProfileInfo(Key as String, location as string) As string
#if TargetMacOS then
Dim s as new Shell
Dim rvalue as string
s.Execute "system_profiler "+location+" | grep "+chr(34)+key+chr(34)
rvalue = trim(NthField(s.Result,":",2))
if rvalue <> "" then Return rvalue
Return "unidentified"
#endif
End Function
Then pass in the following for location and key.
[quote=15559:@Sam Rowlands]Can’t help with Windows, but on the Mac there are a couple of ways. The most common is to use gestalts, but if you use the System Profiler, you can also get the build number of the OS.
Function getProfileInfo(Key as String, location as string) As string
#if TargetMacOS then
Dim s as new Shell
Dim rvalue as string
s.Execute "system_profiler "+location+" | grep "+chr(34)+key+chr(34)
rvalue = trim(NthField(s.Result,":",2))
if rvalue <> "" then Return rvalue
Return "unidentified"
#endif
End Function
Then pass in the following for location and key.
Dim noerror As Boolean
Dim result As Integer
Dim sver As String
Dim sversion As String
Dim os As String
#If TargetMacOS
noerror=System.Gestalt("sysv",result)
If noerror Then
sver=Hex(result)
sversion=sver.Left(2) + "." + sver.Mid(3,1) + "." + sver.Right(1)
OS_CODE=Val(sver.Mid(3,1))
Select Case OS_CODE
Case 0
os="Cheetah"
Case 1
os="Puma"
Case 2
os="Jaguar"
Case 3
os="Panther"
Case 4
os="Tiger"
Case 5
os="Leopard"
Case 6
os="Snow Leopard"
Case 7
os="Lion"
Case 8
os="Mountain Lion"
Case Else
os="Unknown"
End Select
Return "Mac OSX "+os+" "+sversion
Else
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 )
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
os = "Windows 8"
End Select
Str = " Build " + Str( info.Long( 12 ) )
If System.IsFunctionAvailable( "GetVersionExW", "Kernel32" ) Then
Str = Str + " " + Trim( info.WString( 20 ) )
Else
Str = Str + " " + Trim( info.CString( 20 ) )
End If
os = os + Str
Return os
#EndIf
One question, does the compiler directive “#ElseIf TargetWin32” also detect if it is Windows 64 bit? Being that RS/xojo does not have a 64 bit solution, it seems reasonable that it would detect both. However it is also reasonable that it is, exactly what it states it is - 32 bit. So, if it does not detect 64 bit, how to know then it if it IS a windoz OS? And of course which one?
[quote=15567:@Tim Seyfarth]One question, does the compiler directive “#ElseIf TargetWin32” also detect if it is Windows 64 bit? Being that RS/xojo does not have a 64 bit solution, it seems reasonable that it would detect both. However it is also reasonable that it is, exactly what it states it is - 32 bit. So, if it does not detect 64 bit, how to know then it if it IS a windoz OS? And of course which one?
Thanks again all!
Tim[/quote]
TargetWin32 means “Windows using the Win32 APIs” and has nothing to do with 32- or 64-bit. In terms of compile time constants for determining that, you can use Target32Bit and Target64Bit.