Microsoft KB Archive/174561

From BetaArchive Wiki

BUG: OS() Function Returns Incorrect Value Under Windows NT 4.0

ID: Q174561

The information in this article applies to:

  • Microsoft FoxPro for Windows, versions 2.6, 2.6a
  • Microsoft FoxPro for MS-DOS, versions 2.6, 2.6a


The OS() function returns incorrect operating system information when executed from FoxPro for Windows 2.6x or FoxPro for MS-DOS 2.6x running under Windows NT 4.0. The OS() function returns the value DOS 05.00 for the MS-DOS version. Adding the "1" switch available in the OS() function under FoxPro for Windows 2.6x should report the current version of Windows. When running under Windows NT 4.0, the OS(1) function incorrectly identifies the Windows version as Windows 3.10


In FoxPro for Windows 2.6x, you can use the GetWinFlags API to determine whether the application is running on Windows NT 4.0. The code example sends a message to the FoxPro desktop indicating whether Windows NT is the current operating system. It does not include the version of NT. Since the code includes Windows API calls, it will not work in FoxPro for MS-DOS.

   **** Begin Code Example****

   SET LIBRARY TO home() + "foxtools.fll"

   * WF-WINNT represented as the 0-based bit number that must be on
   * in the returned WinFlags() for the program to be running under NT.

   WF_WINNT = 14

   m.getwinflags = RegFN("GetWinFlags", "", "L")
   m.retval = callfn(m.getwinflags)

   IF testbit(m.retval, WF_WINNT)
      ? "Running NT"
      ? "Not running NT"

   * function testbit - determines if a specific bit of a passed number is
   * on/off
   * passed: number (m.number)
   *      bit number (m.bitnum, 0 - 31)
   * returns: .f. for off, .t. for on, .f. for illegal function call

   FUNCTION testbit

   PARAMETERS m.number, m.bitnum

   * number too big - exit
   IF NOT BETWEEN(m.bitnum, 0, 31)
      RETURN .F.

   m.ascii = m.number
   FOR i = 31 TO 0 STEP -1
      m.newascii = MOD(m.ascii, 2 ^ i)
         IF m.bitnum = i
            IF m.newascii # m.ascii
               RETURN .T.
               RETURN .F.
   m.ascii = m.newascii
   **** End Code Example**** 


Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.


The OS() function differs slightly between FoxPro for MS-DOS and FoxPro for Windows 2.6x. In FoxPro for Windows, the OS() function has an optional parameter of 1. This returns the version of Windows. The OS() function simply returns the MS-DOS operating system version.

Steps to Reproduce Behavior

  1. Start FoxPro for MS-DOS on a machine running Windows NT 4.0.
  2. In the Command window, type the following:


         ? OS() 
  3. The OS() function incorrectly reports MS-DOS 05.00.
  4. Start FoxPro for Windows 2.6x on a machine running Windows NT 4.0.
  5. In the Command window, type the following commands:


          ? OS()
          ? OS(1) 
  6. The OS() function incorrectly reports MS-DOS 05.00 as the MS-DOS version and Windows 3.10 as the version of Windows.


For additional information, please see the following articles in the Microsoft Knowledge Base:

Q122353 How to Determine If a VB App is Running Under Windows NT 3.x

Q131371 Determining System Version from a Windows-Based Application

Additional query words: OS

Keywords          : FoxDos FoxWin FxprgGeneral 
Version           : MS-DOS:2.6,2.6a; WINDOWS:2.6,2.6a
Platform          : MS-DOS winnt 
Issue type        : kbbug 

Last Reviewed: August 2, 1999
© 1999 Microsoft Corporation. All rights reserved. Terms of Use.