Determining the operating system

 

horizontal rule

Back Home Next

Author Aart Onkenhout
Date 18-01-2002

 

With the Environment object of PowerBuilder you can't be 100 percent sure what operating system you're on. With one Windows-API you can tell this for sure.

 

Create a structure as follows (PB export code):

 

$PBExportHeader$str_osversioninfo.srs
global type str_osversioninfo from structure
ulong dwOSVersionInfoSize
ulong dwmajorversion
ulong dwminorversion
ulong dwbuildnumber
ulong dwplatformid
character szcsdverion[128]
end type

 

Declare a local external function:

 

Function uLong GetVersionExA( Ref str_osversioninfo lpVersionInfo ) Library "kernel32.dll"

 

Now add a function, e.g. of_IsWin98_2k()

 

/* lstr_VersionInfo.dwMajorVersion:
Windows 95: 4
Windows 98: 4
Windows ME: 4
Windows NT 3.51: 3
Windows NT 4: 4
Windows 2000: 5
Windows XP: 5

lstr_VersionInfo.dwMinorVersion:
Windows 95: 0
Windows 98: 10
Windows ME: 90
Windows NT 3.51: 51
Windows NT 4: 0
Windows 2000: 0
Windows XP: 1
*/

str_OsVersionInfo lstr_VersionInfo

lstr_VersionInfo.dwosversioninfosize = 148
GetVersionExA( lstr_VersionInfo )

If  ( lstr_VersionInfo.dwmajorversion = 4 And lstr_VersionInfo.dwminorversion = 10 ) Or &
    ( lstr_VersionInfo.dwmajorversion = 5 And lstr_VersionInfo.dwminorversion = 0 ) Then
    Return True
End If


Return False