Functions and Directives

Function Os() Foundation

Returns the name of the operating system.

Syntax
Os([<nOsId>]) --> cOsInfo
Parameters
<nOsId>
<nOsId> is one of the following #define constants declared in Os.ch:
Arguments for Os()
Constant Return value
OS_DESCRIPTION *) Complete name with version information
OS_PLATFORM The operating system platform.
OS_FAMILY The operating system family
OS_PRODUCT Short product name
OS_FULLNAME Complete product name
OS_VERSION Up to windows 8 version number formatted to ##.##.####. Windows 10 and later version number formatted to ####.#####
OS_PATCH Information about installed patches/service packs
  1. default value
Return

Os() returns information about the operating system as a character string.

Up to Windows 10 and Windows Server 2016 the version is a two-digit major and two-digit minor number separated by a dot (MM.mm). Starting with Windows 10 and Windows Server 2016, the version is a four-digit number where the first two digits contain the year and the last two digits contain the month (YYMM). The build number, which follows the operating system version separated by a dot, is a five-digit number in this case. In previous Windows versions, the build number consisted of four digits.

Description

The environment function Os() determines the name, the type and version information of the operating system running on the computer. The extended classification into platform, family and product is necessary to be able to react to differences or common things more exact if platform-dependent code is to be executed, like DllCall().

The following table shows examples of return values of platform, family and product:

Samples of return values
Platform Family Product Full name
Define OS_PLATFORM OS_FAMILY OS_PRODUCT OS_FULLNAME
Samples WIN32 WINNT WIN10 Windows 10
WIN32 WINNT WIN8 Windows 8
WIN32 WINNT WIN7 Windows 7
WIN32 WINNT WIN2K Windows 2000
WIN32 WIN9X WIN95 Windows 95

The return value of Os() should always be compared using the == Operator (exact compare). Using the = or the $ operator may result in false results. As an example, the expression "8" $ "Windows 8" results .T. and so does "8" $ "Windows 95/98".

Examples
Sample how to use OS_PLATFORM, OS_FAMILY and OS_PRODUCT
// The sample demonstrates the usage of Os() and how to 
// correctly execute platform-dependent code. 
#include "os.ch" 

PROCEDURE Main 
   LOCAL cAutoExec 

   IF Os(OS_FAMILY) == "WIN9X" 
      IF Os(OS_PRODUCT) != "WINME" 
         cAutoExec := MemoRead("c:\Autoexec.bat") 
      ENDIF 
   ENDIF 
   IF Os(OS_FAMILY) == "WINNT" 
         cAutoExec := MemoRead("c:\Autoexec.nt") 
   ENDIF 
Os()
// The example demonstrates the return values of the function Os() 
#include "os.ch" 

PROCEDURE Main 

   ? Os()                  //  Windows 10 1709 Build 16299 
   ? Os( OS_DESCRIPTION )  //  Windows 10 1709 Build 16299 
   ? Os( OS_PLATFORM )     //  WIN32 
   ? Os( OS_FAMILY )       //  WINNT 
   ? Os( OS_PRODUCT )      //  WIN10 
   ? Os( OS_FULLNAME )     //  Windows 10 
   ? Os( OS_VERSION )      //  1709.16299 

   WAIT 

RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.