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!

Accessing the Windows Registry

Status
Not open for further replies.

xk120

Technical User
Jul 24, 2000
17
0
0
US
How can I access data stored in the Windows Registry?&nbsp;&nbsp;I found Registry.Vcx in the Components Gallery of VFP but I can't get it to work.&nbsp;&nbsp;Help!!!<br><br>Bob
 
wwRegistry is nice from Rick Strahl at west-wind.com.&nbsp;&nbsp;but what won't work with registry.vcx?&nbsp;&nbsp;Did you <FONT FACE=monospace>SET CLASSLIB TO ... ADDITIVE?</font> <p>John Durbin<br><a href=mailto: john@johndurbin.com> john@johndurbin.com</a><br><a href= </a><br>ICQ #9466492<br>
ICQ VFP ActiveList #73897253
 
xk120,
I remembered this thread for a while back and found an answer for you.
from start > run
c:\windows\regedit.exe /e c:\myreg.txt

or from VFP
= RunExe(&quot;c:\windows\regedit.exe&quot; , &quot;/e c:\myreg.txt&quot;)
[tt]
procedure RunExe
lparameters pcExeName, pcParameters
* first parameter required, other - optional
local lcRunString
m.lcRunString = allt(m.pcExeName) + iif(parameters() > 1 , + &quot; &quot; + m.pcParameters , &quot;&quot;)
declare integer WinExec in kernel32 string lpCmdLine, integer uCmdShow
return iif(WinExec(m.lcRunString, 1) > 31 , .t. , .f.)
endproc
[/tt] [sig]<p>David W. Grewe<br><a href=mailto:Dave@internationalbid.net>Dave@internationalbid.net</a><br><a href= > </a><br> [/sig]
 
Look to sample below. This sample shows how to get path of installed EXE file from registry. Note it takes value from folder default value.

Code:
procedure GetExePath
lparameters pcExeName
* returns fill path of EXE file taking it from Windows registry, or empty string


set step on

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
[sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br>[/sig]
 
I too stongly reccommend wwRegistry from Rick Strahl at west-wind.com. It is very handy, actually he has lots of handy utilities there. [sig]<p> Pete<br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>What your mother told you is true! You will go blind! (from moonshine anyway)[/sig]
 
Pete, no doubt that West Wind tools are quite good and have a lot of advantages. I'm using these tools in many places. However, when you need to do something quickly, you just need a code sample to don't spend much time for new tools investigation/buying. [sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br>[/sig]
 
Einar Engström(Programmer)

Fund an article (FoxTalk November 1999 by Doug Henning) that gives the answer to your question

This is an example that vill give the answer whether an CLASS is installed or not:


SET CLASSLIB TO &quot;registry.vcx&quot;
*-* Don’t forget to set the search path to “c:\program\microsoft visual studio\vfp98\ffc\” or the like
#include REGISTRY.H
oReg = NewObject('registry', 'registry.vcx')
llIsThere=oReg.IsKey('NjSrv020.Kamrat', HKEY_CLASSES_ROOT)

IF llIsThere
MessageBox(&quot;NjSrv020.Kamrat is installed&quot;)
ELSE
MessageBox(&quot;NjSrv020.Kamrat is not installed&quot;)
RETURN
ENDIF




Ex2
set classlib to 'C:\Program\Microsoft Visual Studio\Vfp98\FFC\registry.vcx'
LOCAL oReg
oReg = NewObject('registry', 'C:\Program\Microsoft Visual Studio\Vfp98\FFC\registry.vcx')
lcResource=''
oReg.getRegKey('resourceTo', @lcResource, 'Software\Microsoft\VisualFoxPro\6.0\Options', KEY_CURRENT_USER)

MessageBox(“My resourcefile is named: “+lcResource)

Einar Engström
info@tidbok.nu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top