*/***************************************************************************
*#Is File in Windows Registry
*/Program : File_Registry
*/System : FoxPro Library
*/Purpose : Return the full path of a exe file if it is in the windows registry.
*/Syntax : Path = File_Registry(exefile)
*/Returns : Path - string - fullpath and name
*/Parameter : exefile - string - application name (with the exe extension)
*/Defaults : none
*/Requires : Win9x -> WinXP
*/Changes : nothing
*/Calls : External : WinApi AdVapi32.dll
*/Version : 1.0
*/Dated : 09/11/2000
*/Written By: David W. Grewe
*/***************************************************************************
*&Application - Utility
*/***************************************************************************
*/ Record Of Change
*/
*/***************************************************************************
*procedure File_Registry
LPARAMETERS pcExeName
* returns full path of EXE file taking it from Windows registry, or empty string
IF EMPTY(m.pcExeName) OR VARTYPE(m.pcExeName)<>"C" OR PARAMETERS()<1
RETURN ' '
ENDIF
m.pcExeName = JUSTFNAME(m.pcExeName)
DECLARE LONG RegOpenKey IN advapi32 LONG hKey, STRING lpSubKey, LONG @phkResult
DECLARE LONG RegQueryValue IN advapi32 LONG hKey, STRING lpSubKey, STRING @lpValue, LONG @lpcbValue
DECLARE LONG RegCloseKey IN advapi32 LONG hKey
#DEFINE HKEY_LOCAL_MACHINE -2147483646 && bitset(0,31)+2
LOCAL lnErrorRes, phkResult, lpSubKey, lpValue, lpcbValue
phkResult = 0
lpSubKey = 'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths'
lpValue = .NULL.
lpcbValue = 0
lnErrorRes = RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, @phkResult)
IF lnErrorRes # 0 OR phkResult = 0 && Cannot open registry key - unknown error
=MESSAGEBOX('Cannot open Windows registry.',16,'')
RETURN ''
ENDIF
&& open key for exe
lnErrorRes = RegQueryValue(phkResult, m.pcExeName, @lpValue, @lpcbValue)
IF lnErrorRes # 0 OR lpcbValue = 0 && exe-file not registered or path not stored (0 byte length)
lnErrorRes = RegCloseKey(phkResult)
* = messagebox('Exe file not registered in Windows.',16,'')
RETURN ''
ENDIF
lpValue = SPACE(lpcbValue) && in lpcbValue - size of string
lnErrorRes = RegQueryValue(phkResult, m.pcExeName, @lpValue, @lpcbValue)
IF lnErrorRes # 0 OR ISNULL(lpValue) OR EMPTY(lpValue)
&& cannot read default value - unknown error
lnErrorRes = RegCloseKey(phkResult)
=MESSAGEBOX('Cannot read value from registry.',16,'')
RETURN ''
ENDIF
lnErrorRes = RegCloseKey(phkResult)
IF lnErrorRes # 0
&& cannot close key - ignore this error
ENDIF
&& in lpValue - path for exe
lpValue = CHRTRANC(lpValue, CHR(0), '') && delete ending #0
RETURN lpValue