Jump to Real's How-to Main page

Get Windows OS version

You can't rely on the PB Environment Object because it doesn't return enough details. For on W2K system, the Environment returns NT as the operating system. A better way is to call directly the Win API to query the OS version.
[local external function]
FUNCTION ulong GetVersionExA( REF str_osversioninfo lpVersionInfo ) &
LIBRARY "kernel32.dll"
the required structure
[str_osversioninfo]
ulong dwOSVersionInfoSize
ulong dwmajorversion
ulong dwminorversion
ulong dwbuildnumber
ulong dwplatformid
CHARACTER SZCSDVERION[128]
the possible values
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

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

To distinguish between 95 and NT, you also need to check the dwPlatformId value
VER_PLATFORM_WIN32s             0
VER_PLATFORM_WIN32_WINDOWS      1 // WIN95
VER_PLATFORM_WIN32_NT           2 // NT

and from Powerscript, for example
str_osversioninfo lstr_osver

lstr_osver.dwosversioninfosize = 148
GetVersionExA( lstr_osver )

IF (lstr_osver.dwmajorversion = 5 AND lstr_osver.dwminorversion = 1)  THEN
    MessageBox("", "Running on XP");
END IF

If you find this article useful, consider making a small donation
to show your supportfor this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]