×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Microsoft: FoxPro FAQ

Program Source Code

Is a Exe File In the Windows Registry by dgrewe
Posted: 22 Sep 00


/***************************************************************************
*/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


Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close