Working with the registry in Visual Foxpro

Published on by Yousfi Benameur

The majority of these 8 codes below  use the registry.prg class and some of its examples in solution/winapi samples shipped with visual foxpro.

It gives some new demos to work with system registry.

1-find in registry the MRU (most recently used files (MRU)
2-retrieves a registry key with its childs keys as a vfp cursor
3-visual foxpro options set in the registry and their actual values
4-WMI script run from visual foxpro
5-Writing in registry
6-returning all the vfp registered olecontrols  from the registry
7-Associated applications with files extension

8-the Findexecutable API
9-Working with regedit.exe command lines

Suggestions and Bug Reports are always  Welcome

See also:http://yousfi.over-blog.com/2015/02/last-vfp-files-opened-windows-recent.html


*1*This code finds in registry the MRU (most recently used files (MRU)
*It consist in pjx,prg,scx,frx,vcx....vfp extensions                                                        
*The vfp IDE lists only the last proj used in the main vfp menu.
*FoxUser Resource File Structure
*https://msdn.microsoft.com/en-US/library/dz49dz21%28v=vs.80%29.aspx


*Begin code
Publi yform
yform=Newobject("asup")
yform.Show
Read Events
Return
*
Define Class asup As Form
    Height = 422
    Width = 877
    ShowWindow = 2
    AutoCenter = .T.
    Caption = "Working with resource file/most recently used files (MRU)"
    Name = "Form1"

    Add Object combo1 As ComboBox With ;
        Anchor = 768, ;
        BoundColumn = 2, ;
        ColumnCount = 2, ;
        ColumnWidths = "100,100", ;
        Height = 27, ;
        ColumnLines = .F., ;
        Left = 12, ;
        Top = 3, ;
        Width = 193, ;
        Name = "Combo1"

    Add Object grid1 As Grid With ;
        Anchor = 30, ;
        Height = 384, ;
        Left = 3, ;
        Top = 36, ;
        Width = 873, ;
        Name = "Grid1"

    Add Object label1 As Label With ;
        AutoSize = .T., ;
        FontBold = .T., ;
        FontSize = 12, ;
        Anchor = 768, ;
        Caption = "", ;
        Height = 22, ;
        Left = 228, ;
        Top = 12, ;
        Width = 2, ;
        ForeColor = Rgb(255,0,0), ;
        BackColor = Rgb(255,255,128), ;
        Name = "Label1"

    Add Object command1 As CommandButton With ;
        Top = 7, ;
        Left = 708, ;
        Height = 25, ;
        Width = 109, ;
        FontSize = 10, ;
        Anchor = 768, ;
        Caption = "All MRU", ;
        MousePointer = 15, ;
        BackColor = Rgb(255,128,0), ;
        Name = "Command1"

    Procedure my
        Lparameters nButton, nShift, nXCoord, nYCoord
        *--- aevent create an array laEvents
        Aevents( myArray, 0)
        *--- reference the calling object
        loObject = myArray[1]
        If! Messagebox("Open "+Allt(loObject.Value)+" ?",4+64+4096)=6 And File( Allt(loObject.Value))
            Return
        Endi

        Try
            Local m.y
            m.y=Lower(Justext(loObject.Value))
            Do Case
                Case Inlist(m.y,"prg","mpr","htm","html","h","txt")
                    Modi Comm  (Allt(loObject.Value))
                Case m.y=="scx"
                    Modi Form  (Allt(loObject.Value))
                Case m.y="mnx"
                    Modi Menu (Allt(loObject.Value))
                Case m.y="pjx"
                    Modi Proj (Allt(loObject.Value))
                Case m.y="vcx"
                    Modi Class (Allt(loObject.Value))
                Case m.y="frx"
                    Modi Repo (Allt(loObject.Value))

                Case m.y="dbf"
                    Use (Allt(loObject.Value)) Again
                    Brow
                    Use In (Allt(loObject.Value))

                Otherwise
                    Return
            Endcase
        Catch
        Endtry
        *******
        *FoxHelp - IntelliSence
        *When you type certain Visual FoxPro commands, you can use IntelliSense to view a list of available
        *and most recently used files of the appropriate type for each command.
        *The following table lists the commands and the corresponding default file types that IntelliSense
        *searches for and displays.

        *Command  IntelliSense displays files with the following types
        *CD   Files in the current or specified path.
        *DO   .prg, .mpr, .qpr, .fxp, .app, .exe
        *DO FORM   .scx
        *LABEL FORM   .frx, .lbx
        *MODIFY CLASS   .vcx
        *MODIFY COMMAND   .prg, .mpr, .qpr
        *MODIFY DATABASE   .dbc
        *MODIFY FILE   Any file type and extension.
        *MODIFY FORM   .scx
        *MODIFY LABEL   .lbx
        *MODIFY MENU   .mnx
        *MODIFY PROJECT  .pjx
        *MODIFY QUERY   .qpr
        *MODIFY REPORT   .frx
        *MODIFY VIEW   Local and remote views.
        *OPEN DATABASE  .dbc
        *REPORT FORM   .frx, .lbx
        *SET DATABASE   .dbc
        *USE   .dbf, view

        *FoxUser Resource File Structure
        *https://msdn.microsoft.com/en-US/library/dz49dz21%28v=vs.80%29.aspx
    Endproc

    Procedure Init
        Publi m.yrep
        m.yrep=Addbs(Justpath(Sys(16,1)))
        Set Defa To (yrep)

        Use Sys(2005) Again Alias Yres
        Create Cursor ycurs (yMRU c(20),Data c(254))
        Select * From Yres Where Id = "MRU" Order By Id Into Cursor yfoo
        Sele yfoo
        *brow
        Scan
            cData=Data
            xid=Id
            Alines(aa,Substr(cData,3),0,Chr(0))
            For i = 1 To Alen(aa)
                If ! Empty(xid) And ! Empty(aa(i))
                    Insert Into ycurs Value (xid,aa(i))
                Endi
            Endfor
        Endscan

        Use In yfoo
        Sele ycurs

        Set Safe On
        Sele Distinct yMRU From ycurs Into Cursor zcurs
        With Thisform.combo1
            Sele zcurs

            Scan

                Do Case
                    Case Upper(yMRU)="MRUL"
                        xtype= "PJX"
                    Case Upper(yMRU)= "MRUB"
                        xtype="PRG"
                    Case Upper(yMRU)="MRUH"
                        xtype="SCX"
                    Case Upper(yMRU)= "MRUE"
                        xtype="MNX"
                    Case Upper(yMRU)="MRUS"  Or   Upper(yMRU)="MRUJ"
                        xtype="DBF"
                    Case Upper(yMRU)="MRUG"
                        xtype="FRX"
                    Case Upper(yMRU)="MRUI"
                        xtype="VCX"
                    Case Upper(yMRU)="MRUT"
                        xtype="DIR"

                    Otherwise
                        xtype="Unknown"
                Endcase
                .AddItem(m.xtype)
                .List(.NewIndex,2)=yMRU

            Endscan

            .ListIndex=1
            .Style=2
        Endwith

        Use In zcurs
        Sele ycurs
        Locate

        Thisform.combo1.Click()
    Endproc


    Procedure Load
        Close Data All
        Set Safe Off
    Endproc


    Procedure combo1.Click
        Sele ycurs
        Locate
        m.x=Allt(This.Value)
        Sele Data From ycurs Where Allt(yMRU)==m.x Into Cursor zcurs
        Thisform.label1.Caption=Trans(Reccount())+" files"
        With Thisform.grid1
            .RecordSource=''
            .RecordSource="zcurs"
            With .column1.header1
                .FontBold=.T.
                .ForeColor=Rgb(255,255,255)
                .BackColor=Rgb(0,0,140)
            Endwith
            .column1.Width=Thisform.Width-10
            .SetAll("DynamicBackColor", ;
                "IIF(MOD(RECNO( ), 2)=0, RGB(255,200,235)            , RGB(137,200,204))", "Column")
            .Refresh
            .Visible=.T.
            Unbindevent(0)

            Bindevent(Thisform.grid1.column1.text1,;
"mousedown",Thisform,"my")

            Locate
        Endwith
    Endproc

    Procedure grid1.Init
        With This
            .RecordSourceType=1
            .GridLines=0
            .DeleteMark=.F.
            .FontSize=11
            .FontBold=.T.
            .ReadOnly=.T.
            .Themes=.F.
            .Visible=.F.
            .MousePointer=15
        Endwith
    Endproc

    Procedure command1.Click

        Use In zcurs
        Sele ycurs
        Thisform.label1.Caption=Trans(Reccount())+" files"

        With Thisform.grid1
            .RecordSource=""
            .SetAll("visible",.T.,"column")
            .RecordSource="ycurs"
            With .column1.header1
                .FontBold=.T.
                .ForeColor=Rgb(255,255,255)
                .BackColor=Rgb(0,0,140)
            Endwith

            With .column2.header1
                .FontBold=.T.
                .ForeColor=Rgb(255,255,255)
                .BackColor=Rgb(0,0,140)
            Endwith

            .AutoFit()
            .SetAll("DynamicBackColor", ;
                "IIF(MOD(RECNO( ), 2)=0, RGB(255,200,235)            , RGB(137,200,204))", "Column")
            .Refresh
            .Visible=.T.
            Unbindevent(0)
            *bindevent(thisform.grid1.column1.text1,"mousedown",thisform,"my")
            Locate
        Endwith
    Endproc

 procedure destroy
    clea events
    endproc

 

Enddefine
*
*-- EndDefine: asup

*End code

*can use this code to list MRU of
*Unknown,  Command,  File,   Label,  Menu, Query, Report, Form, Class,
*Table, Database,  Project,  Memo, Vue, Procedure,Classlib, View

 

 


Working with the registry  in Visual Foxpro
Working with the registry  in Visual Foxpro

*2*This code retrieves a registry key with its childs keys as a vfp cursor
*this uses the registry.prg class

*Inspired from http://blogs.msdn.com/b/calvin_hsia/archive/2005/05/05/415044.aspx (Hsias)

*Begin code

#Define HKCU -2147483647
Local oreg As "registry" Of Home(1)+"samples\classes\registry.prg"

local m.cpath

*m.cPath="Software\Microsoft\VisualFoxPro\9.0"  &&can try it
m.cPath="Software\Microsoft\Windows"
Create Cursor reg (Level i,Key c(40),Name c(40),Value c(100))
enumreg(m.cPath,HKCU,0)

locate
*Browse Normal
Locate
Browse Name ybrow  Title Trans(reccount())+" Registry entries - "+m.cPath Nowait &&window as oop object

With ybrow
.DeleteMark=.F.
.GridLines=0
.RecordMark=.F.
.SetAll("DynamicBackColor", ;
   "IIF(MOD(RECNO( ), 2)=0, RGB(255,255,255) ;
   , RGB(197,205,200))", "Column")  

Endwith
retu

Procedure enumreg(cPath As String,nhive As Integer,nLevel As Integer)
Local i,oreg,aVals[1,1],aKeys[1]
oreg=Newobject("registry",Home()+"samples\classes\registry.prg")
oreg.openkey(cPath,nhive)
If oreg.EnumKeyValues(@aVals)=0
For i = 1 To Min(Alen(aVals,1),100)
=Replicate(" ",nLevel),nLevel,cPath,aVals[i,1],"=",aVals[i,2]
Insert Into reg Values (nLevel,Replicate(" ",nLevel),aVals[i,1],aVals[i,2])
Endfor
Endif

If oreg.EnumKeys(@aKeys)=0
For i = 1 To Alen(aKeys,1)
=Replicate(" ",nLevel),nLevel,cPath+aKeys[i]
Insert Into reg Values (nLevel,Replicate(" ",nLevel)+aKeys[i],"","")
enumreg(cPath+"\"+aKeys[i],nhive,nLevel+1)
Endfor
Endif

Return

*End code


Working with the registry  in Visual Foxpro

*3*This list all visual foxpro options set in the registry and their actual values
*it uses the class registry.prg

*Begin code
Close Data All

#Define ERROR_SUCCESS 0
#Define C_EXTNOFOUND_LOC "No information available for selected application."
#Define C_NOREGFILE_LOC "The REGISTRY.PRG file needed for this sample could not be found in \Samples\Classes."

Local oReg,regfile
Local cOptionValue,cOptionName,nErrNum
Public aFoxOptions

regfile = Home(2)+"classes\registry.prg"
If !File(m.regfile)
    regfile = Home()+"samples\classes\registry.prg"
    If !File(m.regfile)
        Messagebox(C_NOREGFILE_LOC)
        Return
    Endif
Endif


Set Procedure To (m.regfile) Additive
oReg = Createobject("FoxReg")

Dimension aFoxOptions[1,2]
m.nErrNum = oReg.EnumFoxOptions(@aFoxOptions)
Create Cursor ycurs (FoxOption c(30),Rval c(100))
Sele ycurs
Appe From Array aFoxOptions
*brow title trans(reccount())+" vfp registry installed OPTIONS"
Locate
Browse Name ybrow  Title Trans(Reccount())+" vfp registry installed OPTIONS" Nowait &&window as oop object

With ybrow
    .DeleteMark=.F.
    .autofit()
    .GridLines=0
    .FontSize=10
    .FontBold=.T.
    .RecordMark=.F.
    .SetAll("DynamicBackColor", ;
        "IIF(MOD(RECNO( ), 2)=0, RGB(255,255,255)    , RGB(197,210,191))", "Column")
Endwith
Release Proc (m.regfile)
Retu

*Endcode


Working with the registry  in Visual Foxpro

*4*Sometimes the scripts translation to vfp seem to be difficult because some particular tricks
*as specific vbs commands  using WMI.

*Then we run the vbs froma visual foxpro code as follow for the same and fast result.
*The code below gets the same  result as the vfp code with registry class as above sample.
*the path used is :
HKEY_CURRENT_USER\Software\Microsoft\VisualFoxPro\9.0\Options

*Begin code
Local m.yrep
m.yrep=Addbs(Justpath(Sys(16,1)))
Set Defa To (yrep)
local m.cPath
m.cPath="Software\Microsoft\VisualFoxPro\9.0\Options"    &&put anyregistry Path   here
if file (m.yrep+"out.txt")
dele file (m.yrep+"out.txt")
endi

Local m.myvar
TEXT to m.myvar textmerge  noshow
Const HKEY_CURRENT_USER = &H80000001
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7

strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath ="<<m.cPath>>"
objRegistry.EnumValues HKEY_CURRENT_USER, strKeyPath, arrValueNames, arrValueTypes

x="Using vbs methods from Visual FOXPRO  " & vbCrLf
x=x+"====================================" & vbCrLf & vbCrLf
i=0
For i = 0 to UBound(arrValueNames)
    strText = arrValueNames(i)
    strValueName = arrValueNames(i)

    Select Case arrValueTypes(i)
        Case REG_SZ
            objRegistry.GetStringValue HKEY_CURRENT_USER,strKeyPath, strValueName,strValue
            strText = strText & ": "  & strValue
        Case REG_DWORD
            objRegistry.GetDWORDValue HKEY_CURRENT_USER,strKeyPath, strValueName, intValue
            strText = strText & ": "  & intValue
        Case REG_MULTI_SZ
            objRegistry.GetMultiStringValue HKEY_CURRENT_USER,strKeyPath, strValueName,arrValues
            strText = strText & ": "
            For Each strValue in arrValues
                strText = strText & "   " & strValue
            Next
        Case REG_EXPAND_SZ
            objRegistry.GetExpandedStringValue HKEY_CURRENT_USER,strKeyPath, strValueName,strValue
            strText = strText & ": "  & strValue
       Case REG_BINARY
            objRegistry.GetBinaryValue HKEY_CURRENT_USER,strKeyPath, strValueName,arrValues
            strText = strText & ": "
            For Each strValue in arrValues
                strText = strText & " " & strValue
            Next
        End Select
'Wscript.Echo strText

i=i+1
x= x & i & " " & strText &vbCrLf
Next
'Wscript.Echo x

'output to a txt file

Set objFSO=CreateObject("Scripting.FileSystemObject")
outFile="F:\___yRegistry\out.txt"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write x & vbCrLf
objFile.Close
ENDTEXT
Strtofile(m.myvar,m.yrep+"mytest.vbs")
&&shellexecute
Declare Integer ShellExecute In SHELL32.Dll Integer nWinHandle,;
    STRING cOperation,;
    STRING cFileName,;
    STRING cParameters,;
    STRING cDirectory,;
    INTEGER nShowWindow

result = ShellExecute [0, "open",m.yrep+"mytest.vbs",;
"","",0 ]

Inkey(2)
If File(m.yrep+"out.txt")
    Modi Comm (m.yrep+"out.txt")
Else
    Messagebox("An error occured,16+4096")
Endi

*End code


vbs can be usefull to retrievs some WMI complexes scripts through visual foxpro

vbs can be usefull to retrievs some WMI complexes scripts through visual foxpro


 

*5* must be with priveleges (as administrator ) .the old codes to do that fails to *write even is vfp is used as administrator .here an example:

*Begin code

messagebox("Actual Set talk="+set("TALK"),0+32+4096,'',1000 )
SET TALK ON

SET PROCEDURE TO locfile(HOME(2)+"classes\registry.prg") ADDITIVE
oReg = CreateObject("FoxReg")

release proc (HOME(2)+"classes\registry.prg")
m.nErrNum = oReg.SetFoxOption("TALK","OFF")
messagebox("Set talk="+set("TALK"),0+32+4096,'',1000 )
oReg=null
release  oReg

clea all

*this is Executed with privilege as administrator
SET PROCEDURE TO locfile(HOME(2)+"classes\registry.prg") ADDITIVE  &&the second dont work
oReg = CreateObject("FoxReg")

release proc (HOME(2)+"classes\registry.prg")
m.nErrNum = oReg.SetFoxOption("TALK","ON")
messagebox("Set talk="+set("TALK"),0+32+4096,'',1000 )
oReg=null
release  oReg

*End code


*6*This code retrieves all the vfp registered olecontrols  from the registry
*it uses always the registry.prg class

*Begin code
Publi yform
yform=Newobject("asup")
yform.Show
Read Events
Return
*
Define Class asup As Form
    Height = 438
    Width = 813
    ShowWindow = 2
    AutoCenter = .T.
    Caption = ""
    Name = "Form1"

    Add Object grid1 As Grid With ;
        Anchor = 15, ;
        Height = 442, ;
        Left = 0, ;
        Top = 1, ;
        Width = 816, ;
        Name = "Grid1"

    Procedure Init
        Close Data All
        Local m.yrep,m.lcdest
        m.yrep=Addbs(Justpath(Sys(16,1)))
        Set Defa To (yrep)
        m.lcdest=m.yrep+'yole_registry.txt'
        If File (m.lcdest)
            Dele File (lcdest)
        Endi

        cOptPath = "CLSID"
        Public aControls
        Dimension aControls[1,2]
        Store "" To aControls
        Dimension aCLSIDs[1]

        oReg = Newobject("Registry",Home()+"FFC\REGISTRY")
        If oReg.EnumOptions(@aCLSIDs,cOptPath,"",.T.) # 0
            Return .F.
        Endif
        For i = 1 To Alen(aCLSIDs)
            If m.i%10 = 0
                Wait Window Nowait "Processed "+Str(m.i)+" of "+Str(Alen(aCLSIDs))
            Endif
            Dime aKeys[1]
            Dime aProgID[1,2]
            Dime aControlName[1,2]
            Store "" To aProgID,aControlName

            If oReg.EnumOptions(@aKeys,cOptPath+"\"+aCLSIDs[m.i],"",.T.) = 0
                nPos = Ascan(aKeys,"Control")
                If m.nPos = 0
                    Loop
                Endif
                If !Empty(aControls[1,2])
                    Dimension aControls[ALEN(aControls,1)+1,2]
                Endif
                oReg.EnumOptions(@aControlName,cOptPath+"\"+aCLSIDs[m.i])
                oReg.EnumOptions(@aProgID,cOptPath+"\"+aCLSIDs[m.i]+"\ProgID")
                aControls[ALEN(aControls,1),1] = aControlName[2]
                aControls[ALEN(aControls,1),2] = aProgID[2]
            Endif
        Endfor
        Wait Clear

        Create Cursor ycurs (Name  c(70),OleCClass c(100))
        Append From Array aControls
        * brow
        Display  Memory Like aControls Noconsole To File (lcdest) Noconsole

        *modi comm (lcdest)

        *with thisform.grid1
        *.recordsource="ycurs"
        *locate
        *.autofit()
        *.refresh
        *endwith

        Sele ycurs
        Thisform.Caption=Thisform.Caption+"-VFP Olecontrols in registry :"+Trans(Reccount())+" files"

        With Thisform.grid1
            .RecordSource=''
            .RecordSource="ycurs"
            With .column1.header1
                .FontBold=.T.
                .ForeColor=Rgb(255,255,255)
                .BackColor=Rgb(0,0,140)
            Endwith
            With .column2.header1
                .FontBold=.T.
                .ForeColor=Rgb(255,255,255)
                .BackColor=Rgb(0,0,140)
            Endwith

            .SetAll("DynamicBackColor", ;
                "IIF(MOD(RECNO( ), 2)=0, RGB(205,200,235)            , RGB(197,220,204))", "Column")
            .column1.Width=400
            .column2.Width=400
            Locate
            .Refresh
            *unbindevent(0)
            *bindevent(thisform.grid1.column1.text1,"mousedown",thisform,"my")
        Endwith
    Endproc

    Procedure grid1.Init
        With This
            .RecordSourceType=1
            .GridLines=0
            .DeleteMark=.F.
            .FontSize=11
            .FontBold=.T.
            .ReadOnly=.T.
            .Themes=.F.
            .MousePointer=15
        Endwith
    Endproc

    Procedure Destroy
        Clea Events
    Endproc

Enddefine
*
*-- EndDefine: asup

*End code


Working with the registry  in Visual Foxpro

*7*Using ffc\registry class can retrieve for a given extension the associated application from the *registry, as this sample can demonstrate:

*Begin code

create cursor ycurs (ext c(4),association C(100))
text to m.myvar noshow
PDF
HTM
PRG
SCX
FRX
MPR
H
BMP
PNG
JPG
MP4
WMA
XML
DLL
HTA
ENDTEXT

FOR I=1 TO MEMLINES( m.myvar)
oReg = NewObject("FileReg",HOME()+"FFC\REGISTRY")
   STORE "" TO cExtKey,cAppKey,xext,xassociation
   m.xext=mline(m.myvar,i)
   IF oReg.GetAppPath(m.xext,@cExtKey,@cAppKey) = 0
   m.xassociation=cAppkey  
   ENDIF
 sele ycurs
appe blan
repl ext with m.xext,association with  m.Xassociation
   
oreg=null
endfor

*brow
Locate
Browse Name ybrow  Title Trans(reccount())+" Applications associated " Nowait &&window as oop object

With ybrow
.DeleteMark=.F.
.fontbold=.t.
.GridLines=0
.RecordMark=.F.
.SetAll("DynamicBackColor", ;
   "IIF(MOD(RECNO( ), 2)=0, RGB(255,255,255) ;
   , RGB(177,200,210))", "Column")  

Endwith

*End code

 


*8*This code below using Findexecutable API can do similar goal  as above

*Begin code
Declare Integer FindExecutable In Shell32.Dll ;
    string lpFile, ;
    string lpDirectory, ;
    string @lpResult

local lcResult,lcFile,lcPath,lnSuccess

lcResult = Space(100)
lcFile = Getfile()     &&"MyFile.Ext"
If Empty(lcFile)
    retun .f.
Endi

lcPath = Justpath(lcFile)       &&"MyFilePath"
lnSuccess = FindExecutable(lcFile,lcPath,@lcResult)
If lnSuccess <= 32
 Messagebox("Cannot find the associated program")
Else

MESSAGEBOX("Associated program with "+m.lcfile+chr(13)+"is : "+lcResult)
Endif

*end code


*9*-Regedit.exe command lines

To prevent dialog boxes from appearing when you start Registry Editor, you can add a switch to Regedit.exe at a command prompt to export all or part of the Windows NT or Windows 2000 registry. This makes it a transparent operation and no user input is required.

The additional parameters for Regedit.exe are:
REGEDIT /e File_name.reg regkey_name

File_name.reg - Specifies the text file name to which the Registry should be exported.

Regkey_name - Optionally specifies the key to be exported.


Examples
To transparently export the registry to a text file, click Start, click Run, type

regedit /e c:\output.txt, and then click OK.

To export a registry key, add the specific location to the command such as:
regedit /e c:\output.reg  HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Idconfigdb

REGEDIT [/v|-v] [/s|-s] <FILENAME>  visit:https://support.microsoft.com/en-us/kb/82821

Click on code to select [then copy] -click outside to deselect


*10* added on tuesday 22 march 2016
*vfp/menu/tools/options fure a dialog boxes when can set all vfp configurations.
*if click on button " set as default" all these configurations are wrote in registry
*this code retrieves all this vf registry  settings (found 193)  with native registry class.


#Define ERROR_SUCCESS 0
#Define C_EXTNOFOUND_LOC "No information available for selected application."
#Define C_NOREGFILE_LOC "The REGISTRY.PRG file needed for this sample could not be found in \Samples\Classes."

Local oReg,regfile
Local cOptionValue,cOptionName,nErrNum
Public aFoxOptions

regfile = Home(2)+"classes\registry.prg"
If !File(m.regfile)
    regfile = Home(1)+"samples\classes\registry.prg"
	If !File(m.regfile)
		Messagebox(C_NOREGFILE_LOC)
		Return
	Endif
Endif

Set Procedure To (m.regfile) Additive
oReg = Createobject("FoxReg")
Dimension aFoxOptions[1,2]
m.nErrNum = oReg.EnumFoxOptions(@aFoxOptions)
Create Cursor ycurs (Option c(40),Value c(100))
Appe From Array aFoxOptions

Browse  Name ybrow   Title "VFP registry settings: "+Trans(Reccount())  Nowait    &&window as oop object
With ybrow
    .GridLines=0
    .RecordMark=.F.
    .Width=300
    .Left=100
    .SetAll("DynamicBackColor", "IIF(MOD(RECNO( ), 2)=0, RGB(255,255,255)  , RGB(190,235,200))", "Column")
    .FontBold=.T.
    locate
Endwith



Release Proc (m.regfile)



Working with the registry  in Visual Foxpro
Working with the registry  in Visual Foxpro

Click on code to select [then copy] -click outside to deselect

*11*
created on 07 of february 2017
warning in registry.prg ! (problem rised by Greg Reichert  in UT)
the registry.prg can caveat when the paths are too long(>255 chars).

i copy the registry.prg in a new file  registry1.prg  and made changes in this last replacing the value spac(256) by spac(4096).
i run as administrator regedit.exe, made a new string in  HKEY_CURRENT_USER\Software\Microsoft\VisualFoxPro\9.0\Options :
_ayb (rightclick on pan and new value ("Chaîne" )
in vfp command command _cliptext=repl("A",4000)
 ,go to the key above (options) ,right click on _ayb and paste clipboard.it have a length of 4000 chars.
using the old registry.prg, this key is not retrieved at all but the code works (the cursor browsed)
using the new registry1.prg (with changes) the key is shown at browse (troncated to fit the field legth).

for 256 value the codes works in registry.prg until 253 chars value.
for 4096 the code in regsitry1  works until 4093 chars only (maybe terminating unicode chars)

conclusion: for long paths>253 length must make changes in the registry.prg to make it working.


note : can do this operation from vfp/menu/tools/options and choose a long path in 'files'
press ( values by default"+OK to save in registry.)

lines concerned with changes in registry.prg:
STORE SPACE(256) TO lpbData
STORE SPACE(256) TO lpbData, lpszValue


Click on code to select [then copy] -click outside to deselect

*12* how to add edit prg in the explorer contextuel menu ?
natively vfp9 dont make this operation.it creates "open" in explorer but this runs the prg and dont edit it.
to create a key EditPRG" in explorer this is the manual procedure to do this purpose:
run regedit.exe as administrator
go to the key:
HKEY_CURRENT_USER\Software\Classes\Applications\vfp9.exe\shell
add a new key and name it "EditPRG"
rightclick on the "editPRG" key created and add a new subkey named "command"  (lowercase)
in the right pane dblclick on this key (named by default), a small window appears
(see images below)
paste this (data value):

"C:\Program Files\Microsoft Visual FoxPro 9\vfp9.exe" "C:\Program Files\Microsoft Visual FoxPro 9\yeditprg.prg" "%1

in visual foxpro home (home(1)) create a new prg as below and name it "yeditPRG.prg" +save

lparameters cfilename
if lower(justext(cfilename))=="prg"
MODIFY COMMAND   (cfilename)
else
messagebox("invalid extension!",16+4096,"Error")
endi

its all
go to any prg and rightclick on in the explorer.in the contextuel menu "EditPRG" appears.click on and you edit this prg with vfp9



Working with the registry  in Visual Foxpro
Working with the registry  in Visual Foxpro
To be informed of the latest articles, subscribe:
Comment on this post
J
I ran #3 --- it worked great!
Reply