INF: Code Sample to Find Application Path Using File Extension
PSS ID Number: Q123002
Article last modified on 11-21-1994
PSS database name: FOXPRO

2.50 2.50a 2.50b 2.60 2.60a
WINDOWS

---------------------------------------------------------------------
The information in this article applies to:

- Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a
---------------------------------------------------------------------

SUMMARY
=======
If you know the file extension of a file type that an application uses, you
can quickly determine the full path of that application, by reading the
[EXTENSIONS] section of the WIN.INI, the Windows initialization file. To do
this programatically from FoxPro, use the FOXTOOLS.FLL library to make a
call to a Windows API function, GetPrivateProfileString, as the code
example below demonstrates.

MORE INFORMATION
================
When you run the following code, you will be prompted to enter the
extension. For example, enter a file extension such as XLS. If Excel is
installed, the full path to Excel will be returned.

   SET LIBRARY TO SYS(2004)+"foxtools"
   @ 1,1 GET ext DEFA "     " SAY "Enter the extension: "
   READ
   ext=ALLTRIM(ext)
   IF LEN(ext)=0
      RETURN
   ENDIF
   mpath=REPLICATE(CHR(0),256)
   * Register and call the Windows API function
   mregister=regfn("GetPrivateProfileString","CCC@CIC","I")
   mcall=callfn(mregister,"Extensions",ext,"",@mpath,256,"WIN.INI")
   mpath=ALLTRIM(mpath)
   CNT=OCCURS('\',mpath)  &&find the last backslash in the path
   IF CNT=0
      ? CHR(7)
      WAIT WINDOW "File Extension Not Found"  && in the win.ini file
      RETURN
   ENDIF
   x=AT('\',mpath,CNT)  && find the position of the last backslash
   mpath=SUBSTR(mpath,1,x-1)  && extract just the path
   @ 2,1 SAY "The path to the executable is " + mpath

Additional reference words: FoxWin 2.50 2.50a 2.50b 2.50c 2.60
KBCategory: kbprg kbcode
KBSubcategory:

=============================================================================
Copyright Microsoft Corporation 1994.