Microsoft KB Archive/121441

= Code Sample to Find Application Path Using File Extension =

Article ID: 121441

Article Last Modified on 11/17/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft FoxPro 2.6 Standard Edition
 * Microsoft FoxPro 2.6a Standard Edition

-



This article was previously published under Q121441



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 3.x 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.

NOTE: For backward compatibility, Visual FoxPro still supports FOXTOOLS.FLL (included in earlier FoxPro versions), the Visual FoxPro API library that allows calls to 16-bit .DLL functions. However, in Visual FoxPro, the DECLARE command is the preferred method for calling .DLL functions.



MORE INFORMATION
NOTE: This example only works with Windows version 3.x (16-bit versions), which use the WIN.INI file. Windows NT and Windows 95 use the Registry instead of WIN.INI.

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. 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 query words: VFoxWin FoxWin 2.50 2.50a 2.50b 2.50c

Keywords: kbcode KB121441

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.