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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Registry support in 2.6

Status
Not open for further replies.

rohbe

IS-IT--Management
Aug 30, 2001
76
0
0
US
Can I access the Registry in 2.6
Is there a way that using RUN Regedit I can get a registry key returned or even update a Registry Key from within 2.6.

Thanks,
Jean
 
Jean,
Maybe in FP for Windows (using CALL32 - do a Search above for links), but as likely in FP DOS.

About the only way I can think of generically is to use text merge or low-level IO to write out a script file and then execute it. Unfortunately there isn't any(?) way to track it's progress or success, or even know whether WSH is installed and available on a given users system.

Here is a sample (similar to what you want, but totally different) that I picked up on the newsgroups:
Code:
*:* FPD + Win/NT -> WSH (Network redirection of printers & Calling DLL's build with VB 5.0)

Some time ago I read an interesting article in Win/NT Mag. concerning WSH = Windows Scripting Host.  WSH can be downloaded for free from the microsoft web.  As I still have a lot of FPD26 code in production (no time to rewrite) I saw an opertunity to integrate FPD26 tighter into the operating system and integrate FPD26 with other Win32 applications written in VB by using WSH.
 
Problem 1 I solved:  Network redirection of printers...  Shelling out of FPD26 towards the command prompt and calling the NET USE command never was a good solution.  So I now use the following code:
 
sPrtPort = "LPT1:"
sPrtMap = "\\PRTSERVER\PRINTER1" 
OutChan = FCREATE("C:\FOXPRO\WSHPrint.VBS")
IF OutChan > 0
   =FPUT(OutChan,'Set WshNetwork = WScript.CreateObject("WScript.Network")')
   =FPUT(OutChan,'On Error Resume Next')
   =FPUT(OutChan,'WshNetwork.RemovePrinterConnection "' + sPrtPort + '"')
   =FPUT(OutChan,'WshNetwork.AddPrinterConnection "' + sPrtPort + '", "' + sPrtMap + '"')
   =FCLOSE(OutChan)
   Tmp_4 = "RUN /0 CScript C:\FOXPRO\WSHPrint.VBS //B //NoLogo //T:60"
   &Tmp_4
   SET PRINTER TO &sPrtPort
ENDIF

The above example is an extract of the full code I have under WSH.  You can add checking of the printer connection so that you don't add new code.  In a comparable way you can add shortcuts to the desktop... see [URL unfurl="true"]www.microsoft.com\management[/URL] and check for WSH.
 
Problem 2 I solved: Calling DLL's build with VB 5.0 to access information stored in *.MDB or other non accessible DB's from FPD26.
 
MS Office (Excel, Word) is used by several persons on a daily basis.  The macro language build into Excel / Word is, I'm sorry to say, not VFP but Visual Basic 5.0.  So several programs (macros) have been written in the past to access databases.  Through time the code became so big that I had to start using VB 5.0.  In VB 5.0 I compiled into DLL's (ActiveX InProcess Servers) which were then called from Excel and Word and from standalone applications.  After a short while I had two different systems up and running.  One system in FPD26 which I was rewriting slowly but which wasn't able to communicate directly with the new code running under Excel / Word.  So with WSH I can now communicate.
 
With the above example I call the shipment print procedure written in VB out of FPD26.  The whole process is transparent towards the users.  The users doesn't notice any difference except that now the printouts of the FPD26 and the VB code are identical.  I've also experience that the overhead created by the FPD26 and the WSH link is neglectible.
 
OutChan = FCREATE("C:\FOXPRO\WSHPInst.VBS")
IF OutChan > 0
   =FPUT(OutChan,'Set oPrt = WScript.CreateObject("PrintEngine.ShipmentPrint")')
   =FPUT(OutChan,'oPrt.ShipmentPrint "' + m.ShipMent + '"')
   =FPUT(OutChan,'WScript.DisconnectObject oPrt')
   =FPUT(OutChan,'Set oPrt = Nothing')
   =FCLOSE(OutChan)
   Tmp_4 = "RUN /0 CScript C:\FOXPRO\WSHPInst.VBS //B //NoLogo //T:60"
   &Tmp_4
ENDIF
 
Suddenly my FPD26 has gained value because it can communicate not only with the operating system but also because I can now call Dll's in an easy way.
 
I though it was necessary to share this piece of information with you as I've been looking for a WSH solution for quite some time.  Also this discussion group has been an overwhelming source of information for me for many years now.
 
Kind regards,
bibi,
Donald Neyt.
Rick
 
I don't know of a way to read a registry key other than using API calls, as Rick mentioned, but another method of adding a registry key would be to create your registry file, then run regedit to merge it.
Below is temp.reg I just exported from my registry, which shows the printer ports. You can either export from your registry and import on another machine, or create your own to import/merge. All of this should go without saying, that playing with the registry is dangerous, and you should make a backup first!
You may need to check your documentation for proper syntax also. The code below is contained in C:\temp\PrtPorts.reg.
Code:
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts]
"HPLJ4100"="winspool,Ne01:,15,45"
"Fax Driver"="winspool,Ne02:,15,45"
"Fax"="winspool,Ne03:,15,45"

Due to the length of the string, let me point out that
"[HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts]"
should be one contiguous line.

To merge:
Code:
MyCmd = "RUN /0 regedit  C:\temp\PrtPorts.reg"
&MyCmd

To experiment, just fire up your registry editor and try exporting a branch or two. You can modify them and test them from there.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
3rd alternative - Write it in VFP and call it from 2.6.

Sounds like there are no really good ways to do this in FPW.

Thanks Rich and Dave

Jean S.
 
To add a regsitry key you could create a .REG file and run that from Foxpro.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top