Kbase P25159: ABL/4GL: How to determine the Windows Version, Build and Service pack under which the current 4GL/AB
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  3/5/2010 |
|
Status: Verified
GOAL:
ABL/4GL: How to determine the Windows Version, Build and Service pack under which the current 4GL/ABL session is running?
GOAL:
How to call WIN API GetVersionEx function to obtain extended information about the version of the operating system that is currently running?
GOAL:
What is the Windows Operating System Version, Build and Service Pack of the current 4GL/ABL Session?
GOAL:
How to programmatically know the Windows Operating System Version, Build and Service Pack of the current 4GL/ABL Session?
FACT(s) (Environment):
Progress 8.x
Progress 9.x
OpenEdge 10.x
Windows
OpenEdge Category: Language (4GL/ABL)
FIX:
A 4GL/ABL application may be running under any of the major versions of Windows and any of the minor subversions and Service Packs. The exact Windows version makes a difference when the specific system information determines which system APIs to call because each Windows version adds new API calls while rendering some older ones obsolete. The following procedure demonstrates how to call WIN API GetVersionEx function to obtain extended information about the version and service pack of the operating system under which the 4GL/ABL is running: /*
dwOSVersionInfoSize
Size of this data structure, in bytes.
Set this member to sizeof(OSVERSIONINFOEX) before calling the GetVersionEx function. dwMajorVersion
Major version number of the operating system. This member can be one of the following values.
Windows 95 4
Windows 98 4
Windows Me 4
Windows NT 3.51 3
Windows NT 4.0 4
Windows 2000 5
Windows XP 5
Windows Server 2003 family 5 dwMinorVersion
Minor version number of the operating system. This member can be one of the following values.
Windows 95 0
Windows 98 10
Windows Me 90
Windows NT 3.51 51
Windows NT 4.0 0
Windows 2000 0
Windows XP 1
Windows Server 2003 family 2 dwBuildNumber
Build number of the operating system.
Windows Me/98/95: The low-order word contains the build number of the operating.
The high-order word contains the major and minor version numbers. dwPlatformId
Operating system platform. This member can be one of the following values.
VER_PLATFORM_WIN32s Win32s on Windows 3.1 0.
VER_PLATFORM_WIN32_WINDOWS Windows 95, Windows 98, or Windows Me. 1.
VER_PLATFORM_WIN32_NT Windows NT/2000/XP/Server 2003 family 2. szCSDVersion
Pointer to a null-terminated string, such as "Service Pack 3", that indicates the latest Service Pack
installed on the system. If no Service Pack has been installed, the string is empty.
Windows Me/98/95: Pointer to a null-terminated string that indicates additional version information.
For example, " C" indicates Windows 95 OSR2 and " A" indicates Windows 98 Second Edition.wProductType
This 8-bit identifier provides additional information about the system and is used to distinguish Windows 7, Windows Vista, Windows Server 2008 and Windows 2008 R2.
*/
DEFINE VARIABLE dwOSVersionInfoSize AS INTEGER NO-UNDO INITIAL 156.
DEFINE VARIABLE OSVERSIONINFOEX AS MEMPTR NO-UNDO.
DEFINE VARIABLE VER_PLATFORM_WIN32s AS INTEGER NO-UNDO INITIAL 0.
DEFINE VARIABLE VER_PLATFORM_WIN32_WINDOWS AS INTEGER NO-UNDO INITIAL 1.
DEFINE VARIABLE VER_PLATFORM_WIN32_NT AS INTEGER NO-UNDO INITIAL 2.
DEFINE VARIABLE VER_NT_WORKSTATION AS INTEGER NO-UNDO INITIAL 1.
DEFINE VARIABLE VER_NT_SERVER AS INTEGER NO-UNDO INITIAL 3.
DEFINE VARIABLE dwMajorVersion AS INTEGER NO-UNDO.
DEFINE VARIABLE dwMinorVersion AS INTEGER NO-UNDO.
DEFINE VARIABLE dwBuildNumber AS INTEGER NO-UNDO.
DEFINE VARIABLE dwPlatformId AS INTEGER NO-UNDO.
DEFINE VARIABLE szCSDVersion AS CHARACTER NO-UNDO.
DEFINE VARIABLE wServicePackMajor AS INTEGER NO-UNDO.
DEFINE VARIABLE wServicePackMinor AS INTEGER NO-UNDO.
DEFINE VARIABLE wSuiteMask AS INTEGER NO-UNDO.
DEFINE VARIABLE wProductType AS INTEGER NO-UNDO.
DEFINE VARIABLE wReserved AS INTEGER NO-UNDO.
DEFINE VARIABLE cOperatingSystem AS CHARACTER NO-UNDO.
DEFINE VARIABLE iReturnResult AS INTEGER NO-UNDO.
PROCEDURE GetVersionExA EXTERNAL "KERNEL32.DLL" :
DEFINE INPUT PARAMETER OSVERSIONINFOEX AS LONG.
DEFINE RETURN PARAMETER ReturnValue AS LONG.
END PROCEDURE.
SET-SIZE(OSVERSIONINFOEX) = dwOSVersionInfoSize.
PUT-LONG(OSVERSIONINFOEX,1) = dwOSVersionInfoSize.
RUN GetVersionExA (GET-POINTER-VALUE(OSVERSIONINFOEX), OUTPUT iReturnResult ).
ASSIGN
dwMajorVersion = GET-LONG(OSVERSIONINFOEX, 5).
dwMinorVersion = GET-LONG(OSVERSIONINFOEX, 9)
dwBuildNumber = GET-LONG(OSVERSIONINFOEX, 13)
dwPlatformId = GET-LONG(OSVERSIONINFOEX, 17)
szCSDVersion = GET-STRING(OSVERSIONINFOEX, 21)
wServicePackMajor = GET-BYTES (OSVERSIONINFOEX, 149, 2)
wServicePackMinor = GET-BYTES (OSVERSIONINFOEX, 151, 2)
wSuiteMask = GET-BYTES (OSVERSIONINFOEX, 153, 2)
wProductType = GET-BYTE (OSVERSIONINFOEX, 155)
wReserved = GET-BYTE (OSVERSIONINFOEX, 156).
CASE dwPlatformId:
WHEN VER_PLATFORM_WIN32s THEN
cOperatingSystem = "Windows 3.1".
WHEN VER_PLATFORM_WIN32_WINDOWS THEN
IF dwMajorVersion = 4 AND dwMinorVersion = 0 THEN
cOperatingSystem = "Windows 95".
ELSE IF dwMajorVersion = 4 AND dwMinorVersion = 10 THEN
cOperatingSystem = "Windows 98".
ELSE IF dwMajorVersion = 4 AND dwMinorVersion = 90 THEN
cOperatingSystem = "Windows Me".
WHEN VER_PLATFORM_WIN32_NT THEN
IF dwMajorVersion = 3 AND dwMinorVersion = 51 THEN
cOperatingSystem = "Windows NT 3.51".
ELSE IF dwMajorVersion = 4 AND dwMinorVersion = 0 THEN
cOperatingSystem = "Windows NT 4.0".
ELSE IF dwMajorVersion = 5 AND dwMinorVersion = 0 THEN
cOperatingSystem = "Windows 2000".
ELSE IF dwMajorVersion = 5 AND dwMinorVersion = 1 THEN
cOperatingSystem = "Windows XP".
ELSE IF dwMajorVersion = 5 AND dwMinorVersion = 2 THEN
cOperatingSystem = "Windows Server 2003 family".
ELSE IF dwMajorVersion = 6 AND dwMinorVersion = 0
THEN DO:
IF wProductType = VER_NT_WORKSTATION THEN
cOperatingSystem = "Windows Vista".
ELSE cOperatingSystem = "Windows Server 2008".
END.
ELSE IF dwMajorVersion = 6 AND dwMinorVersion = 1
THEN DO:
IF wProductType = VER_NT_WORKSTATION THEN
cOperatingSystem = "Windows 7".
ELSE cOperatingSystem = "Windows Server 2008 R2".
END.
END CASE.
MESSAGE
"Operating System:" "~t" cOperatingSystem "~n"
"Build Number:" "~t" dwBuildNumber "~n"
"Service Pack" "~t" szCSDVersion "~n"
VIEW-AS ALERT-BOX INFO BUTTONS OK..