PRB: SYS(2004) Returns Incorrect Directory

Last reviewed: January 22, 1996
Article ID: Q140614
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0

SYMPTOMS

SYS(2004) returns incorrect information. According to the online Help file, SYS(2004) should return the name of the directory or folder from which Visual FoxPro was started. However, if you are running several instances of Visual FoxPro, the SYS(2004) function returns only the directory from which the first instance was started.

CAUSE

Executable files created in Visual FoxPro are not standalone applications. They rely on the Vfp300.esl as a runtime library. The SYS(2004) function returns the location of this file during run time. Even if you have multiple copies of this run-time library, the operating system will not load several instances into memory; it only opens one copy. That is why the SYS(2004) function only reports the location of the first one that was started.

RESOLUTION

You can use one of the following alternate methods to obtain the startup directory:

  • Use the CURDIR() function to retrieve the working directory.
  • Store the name of the startup directory in a lookup table.
  • Write the location of the directory to an .ini file by using API calls.

STATUS

This behavior is by design.

MORE INFORMATION

For information about an alternative method of obtaining the path to the installation, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q138937
   TITLE     : How to Tell Which Directory Holds a Visual FoxPro App's .Exe

Steps to Reproduce Behavior

  1. Create a program file that contains the following line repeated twice:

    WAIT WINDOW SYS(2004)

  2. Add this program to a new project, and build an executable.

  3. Create a second, new project and add the same program to it. Create this executable with a different name and save it into a different directory.

  4. Copy the Vfp300.esl file into both of the directories, or place the Windows\System directory in your PATH statement.

  5. Create icons for each of the executables, and set the working directories to the executable's location.

  6. Try running each application separately. The WAIT WINDOW will report the correct directory for each program.

  7. Close the executables if they are open.

  8. Start one of the executables. While it is waiting for you to press a key, start the other executable. You will now see that the second instance reports the same starting directory as the first one.


Additional reference words: 3.00 VFoxWin
KBCategory: kbprg kbprb
KBSubcategory: FxprgGeneral


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 22, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.