Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is a Exe File In the Windows Registry

Program Source Code

Is a Exe File In the Windows Registry

by  dgrewe  Posted    (Edited  )
[tt]
/***************************************************************************
*/Program : IsFileInReg
*/System : FoxPro Library
*/Purpose : Return the full path of a exe file if it is in the windows registry.
*/Syntax : Path = IsFileInReg(exefile)
*/Returns : Path - string - fullpath and name
*/Parameter : exefile - string - application name (with the exe extension)
*/Defaults : none
*/Requires : Win9x, WinNT
*/Changes : nothing
*/Calls : External : WinApi AdVapi32.dll
*/Version : 1.0
*/Dated : 09/11/2000
*/Written By: David W. Grewe
*/***************************************************************************
*& type of prg :
*/***************************************************************************
*/ Record Of Change
*/
*/***************************************************************************
lparameters pcExeName
* returns fill path of EXE file taking it from Windows registry, or empty string
if empty(m.pcExeName) .or. type("m.pcExeName") != "C" .or. parameter() < 0.5
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.')
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.')
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.')
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
[/tt]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top