Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Oct 17, 2019 5:42 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Code to find Window version
PostPosted: Fri Aug 27, 2010 2:49 am 
Offline

Joined: Sat Aug 04, 2007 3:43 pm
Posts: 51
Hi,
I have no clue other then #if targetwin32... to determine that it is a windows application.
But I would like to know further if the user OS is XP, Vista or Windows 7.
Has anyone a short code to share a solution with me?
Thanks!
Peter


Top
 Profile  
Reply with quote  
 Post subject: Re: Code to find Window version
PostPosted: Fri Aug 27, 2010 3:41 am 
Offline
User avatar

Joined: Fri Jun 05, 2009 11:50 am
Posts: 348
Location: Hamburg, Germany
something like this shoul do

make a new method in app

Function getOSVersion() As string
dim os as string

//get os
#if TargetMacOS
OS = "Mac OS"

//be more specific of OS Version
dim sys1, sys2, sys3 as Integer
call System.Gestalt("sys1", sys1)
call System.Gestalt("sys2", sys2)
call System.Gestalt("sys3", sys3)

select case sys1
case 10
os = "Mac OSX"
select case sys2
case 0
os = "Mac OSX Chetaah"
case 1
os = "Mac OSX Puma"
case 2
os = "Mac OSX Jaguar"
case 3
os = "Mac OSX Panther"
case 4
os = "Mac OSX Tiger"
case 5
os = "Mac OSX Leopard"
case 6
os = "Mac OSX Snow Leopard"
end select
end select

os = os + " "+str(sys1)+"."+str(sys2)+"."+str(sys3)

#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

if info.Long( 4 ) = 4 then
if info.Long( 8 ) = 0 then
os = "Windows 95/NT 4.0"
elseif info.Long( 8 ) = 10 then
os = "Windows 98"
elseif info.Long( 8 ) = 90 then
os = "Windows Me"
end if
elseif info.Long( 4 ) = 3 then
os = "Windows NT 3.51"
elseif info.Long( 4 ) = 5 then
if info.Long( 8 ) = 0 then
os = "Windows 2000"
elseif info.Long( 8 ) = 1 then
os = "Windows XP"
elseif info.Long( 8 ) = 2 then
os = "Windows Server 2003"
end if
elseif info.long(4) = 6 then
if info.long(8) = 0 then
os = "Windows Vista"
elseif info.long(8) = 1 then
os = "Windows 7"
end if
end if

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


#elseif TargetLinux
OS = "Linux"
path = ""
#endif

return os
End Function


(taken from my dump file creation in unhandles exception )

This will return a String with the actual OS Version and can be called from everywhere with

dim os as string

os = getOSVersion

_________________
Best regards

Stefan

Mac OSX Mountain Lion (latest Release) on a MacBook Pro 2.66 GHz Intel Core i7/ RB Professional 2011 Release 3


Top
 Profile  
Reply with quote  
 Post subject: Re: Code to find Window version
PostPosted: Sun Aug 29, 2010 9:01 pm 
Offline

Joined: Mon Jun 23, 2008 3:04 pm
Posts: 121
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

also see

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\ProductName


Top
 Profile  
Reply with quote  
 Post subject: Re: Code to find Window version
PostPosted: Mon Aug 30, 2010 2:47 am 
Offline

Joined: Sat Aug 04, 2007 3:43 pm
Posts: 51
Hi Stefan,

Thank you very much! Works beautifully.

Peter


Top
 Profile  
Reply with quote  
 Post subject: Re: Code to find Window version
PostPosted: Tue Aug 21, 2012 7:30 am 
Offline

Joined: Mon Jan 22, 2007 9:47 am
Posts: 131
i updated the example, in order to distinguish between Server 2003 (R2), Server 2008 (R2), Windows 8, Server 2012, ...


Private Function System_Version_Windows(pbServicePack As Boolean = True, pbBuildNumber As Boolean = False) As String
#if TargetWin32
try
'GetVersionEx function
'http://msdn.microsoft.com/en-us/library/windows/desktop/ms724451(v=vs.85).aspx

'OSVERSIONINFOEX structure
'http://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx

'GetSystemMetrics function
'http://msdn.microsoft.com/en-us/library/windows/desktop/ms724385(v=vs.85).aspx

Soft Declare Sub GetVersionExA lib "Kernel32" ( info as Ptr )
Soft Declare Sub GetVersionExW lib "Kernel32" ( info as Ptr )
Soft Declare Function GetSystemMetrics lib "User32" ( metrixIndex As Integer ) As Integer

Dim info As MemoryBlock
Dim iMajorVersion, iMinorVersion, iBuildNumber, iPlatformID As Integer
Dim sServicePack As String
Dim iServicePackMajor, iServicePackMinor As Integer
Dim iSuiteMask As Integer
Dim iProductType As Integer

Dim iSPOffset As Integer
if System.IsFunctionAvailable( "GetVersionExW", "Kernel32" ) then
iSPOffset = 20 + (2 * 128)
info = new MemoryBlock( iSPOffset + 6 + 2)
info.Long( 0 ) = info.Size

GetVersionExW( info )

iMajorVersion = info.Long( 4 )
iMinorVersion = info.Long( 8 )
iBuildNumber = info.Long( 12 )
iPlatformID = info.Long( 16 )
sServicePack = info.WString( 20 )
iServicePackMajor = info.Int16Value( iSPOffset )
iServicePackMinor = info.Int16Value( iSPOffset + 2)
iSuiteMask = info.Int16Value( iSPOffset + 4)
iProductType = info.Byte( iSPOffset + 6)

else
iSPOffset = 20 + 128
info = new MemoryBlock( iSPOffset + 6 + 2)
info.Long( 0 ) = info.Size

GetVersionExA( info )

iMajorVersion = info.Long( 4 )
iMinorVersion = info.Long( 8 )
iBuildNumber = info.Long( 12 )
iPlatformID = info.Long( 16 )
sServicePack = info.CString( 20 )
iServicePackMajor = info.Int16Value( iSPOffset )
iServicePackMinor = info.Int16Value( iSPOffset + 2)
iSuiteMask = info.Int16Value( iSPOffset + 4)
iProductType = info.Byte( iSPOffset + 6)

end if

dim str as String
select case iMajorVersion
case 6
select case iMinorVersion
case 0
if (iProductType <= 1) then
str = "Vista"
else
str = "Server 2008"
end if
case 1
if (iProductType <= 1) then
str = "7"
else
str = "Server 2008R2"
end if
case 2
if (iProductType <= 1) then
str = "8"
else
str = "Server 2012"
end if
end select
case 5
select case iMinorVersion
case 2
if System.IsFunctionAvailable( "GetSystemMetrics", "User32" ) and (GetSystemMetrics(89) > 0) then
str = "Server 2003R2"
else
str = "Server 2003"
end if
case 1
str = "XP"
case 0
str = "2000"
end select
case 4
select case iMinorVersion
case 90
str = "Me"
case 10
str = "98"
case 0
str = "95/NT 4.0"
end select
case 3
str = "NT 3.51"
end select

if (str = "") then str = Str(iMajorVersion) + "." + Str(iMinorVersion)

if pbServicePack and (sServicePack <> "") then
sServicePack = Replace(sServicePack, "Service Pack", "SP")
str = str + " (" + Trim(sServicePack) + ")"
end if

if pbBuildNumber then str = str + " Build " + Str( iBuildNumber )

return Trim(str)
catch err As RuntimeException
return ""
end try
#endif
End Function


Top
 Profile  
Reply with quote  
 Post subject: Re: Code to find Window version
PostPosted: Thu Aug 23, 2012 6:18 am 
Offline

Joined: Sun Nov 26, 2006 11:01 am
Posts: 58
For Windows you will find a routine in the Windows Functionality Suite:
Examples/Windows OS specific/Windows Functionality Suite 2.5/Windows Functionality Suite

And then: System Information/Modules/OSVersionInformation

However, it does not support Windows 7 and 8 yet, but by looking on the methods you will find out how to check for them.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group