DOCUMENT:Q121441  08-NOV-1994  [FOXPRO]
TITLE   :INF: Code Sample to Find Application Path Using File Extension
PRODUCT :Microsoft FoxPro
PROD/VER:2.50 2.60 2.60a
OPER/SYS:WINDOWS
KEYWORDS:kbprg kbcode

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

 - Microsoft FoxPro for Windows, versions 2.5x, 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 file (the Windows initialization file).
To do this programmatically from FoxPro, you can use the FOXTOOLS.FLL
library to make a call to the Windows API GetPrivateProfileString()
function, as the code example below demonstrates.

MORE INFORMATION
================

When you run this code, you will be prompted to enter the extension. For
example, enter a file extension such as "XLS" (without the quotation marks)
and press ENTER. If Microsoft Excel is installed, the full path to
Microsoft Excel will be returned.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN
RISK. Microsoft provides this code "as is" without warranty of any kind,
either express or implied, including but not limited to the implied
warranties of merchantability and/or fitness for a particular purpose.

   SET LIBRARY TO SYS(2004)+"foxtools"
   @ 1,1 GET ext DEFAULT "     " 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:

=============================================================================

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.

Copyright Microsoft Corporation 1994.