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

Reading registry in VFP 1

Jureczek13

Programmer
Apr 19, 2023
11
CA
Under HKEY_LOCAL_MACHINE\SOFTWARE\Native Instruments\ I have many keys, each represents name of library (for example: "Symphobia 2", "Electric Keys", "Guitar Swell", etc.)
I need to get a list of all those keys, and for each key get a value of a sub-key "ContentDir".

1746494082382.png
 
Are you familiar with the Stonefield Database Toolkit (stonefield.com). I'm thinking Doug Hennig, the creator of that, has something to read the registry in there. It's open source now so it may be best to find it on GitHub. Also, Rick Strahl might have something in his tools at www.west-wind.com.
 
Jureczek13,

This goes untested, since I don't have that software on my machine:

Code:
#DEFINE HKEY_LOCAL_MACHINE    0x80000002
#DEFINE INSTRUMENTS            "SOFTWARE\Native Instruments"

SET CLASSLIB TO (HOME(1) + "FFC\registry") ADDITIVE

LOCAL Reg AS registry

m.Reg = CREATEOBJECT("registry")

LOCAL ARRAY Entries[1]
LOCAL NativeInstruments AS Integer

m.Reg.OpenKey(INSTRUMENTS, HKEY_LOCAL_MACHINE, .F.)
m.Reg.EnumKeys(@m.Entries)
m.Reg.CloseKey()

LOCAL Instrument AS String
LOCAL kValue AS String

CREATE CURSOR curInstruments (Instrument Varchar(254), ContentDir Varchar(254))

IF VARTYPE(m.Entries[1]) != "L"

    FOR EACH m.Instrument IN m.Entries

        m.Reg.OpenKey(INSTRUMENTS + "\" + m.Instrument, HKEY_LOCAL_MACHINE, .F.)

        IF m.Reg.GetKeyValue("ContentDir", @m.kValue) == 0

            INSERT INTO curInstruments VALUES (m.Instrument, m.kValue)

        ENDIF

        m.Reg.CloseKey()

    ENDFOR

ENDIF

BROWSE
 
You don't need Stonefield Databse Toolkit to do this, as atlopes sample already proves.

But just open the help, search registry and you're pointed to a Registry Access Foundation Class:
1746512789531.png
Foundation classes (aka FoxPro Foundation Classes - FFC) are a set of libraries that come with VFP and you'll also find this in earlier VFP versions, I guess since 6, maybe even earlier, too.
The help topic describes this registry library, what it offers and how it's used and atlopes is using exactly that.
 
Last edited:
Jureczek13,

This goes untested, since I don't have that software on my machine:

Code:
#DEFINE HKEY_LOCAL_MACHINE    0x80000002
#DEFINE INSTRUMENTS            "SOFTWARE\Native Instruments"

SET CLASSLIB TO (HOME(1) + "FFC\registry") ADDITIVE

LOCAL Reg AS registry

m.Reg = CREATEOBJECT("registry")

LOCAL ARRAY Entries[1]
LOCAL NativeInstruments AS Integer

m.Reg.OpenKey(INSTRUMENTS, HKEY_LOCAL_MACHINE, .F.)
m.Reg.EnumKeys(@m.Entries)
m.Reg.CloseKey()

LOCAL Instrument AS String
LOCAL kValue AS String

CREATE CURSOR curInstruments (Instrument Varchar(254), ContentDir Varchar(254))

IF VARTYPE(m.Entries[1]) != "L"

    FOR EACH m.Instrument IN m.Entries

        m.Reg.OpenKey(INSTRUMENTS + "\" + m.Instrument, HKEY_LOCAL_MACHINE, .F.)

        IF m.Reg.GetKeyValue("ContentDir", @m.kValue) == 0

            INSERT INTO curInstruments VALUES (m.Instrument, m.kValue)

        ENDIF

        m.Reg.CloseKey()

    ENDFOR

ENDIF

BROWSE
Thanks for your answer. I tested it in 2 cases:
1. Using "HKEY_CURRENT_USER\SOFTWARE\Native Instruments" - this retrieves all the keys, but some sub-keys, not all.
2. Using "HKEY_LOCAL_MACHINE\SOFTWARE\Native Instruments" - this retrieves some keys, and some sub-keys.

What I'm doing now is: export registry to .reg file and read the file and retrieve all the data I need
 
Your initial post and its screenshot clearly states keys are in HKEY_LOCAL_MACHINE. If you also have them in HKEY_CURRENT_USER, that's just needing to read both branches. No big deal. Well, if youre fine with manually exorting into reg files and reading them out, okay.
 
When I export registry key to .reg file, and then when I read the first line: "Windows Registry Editor Version 5.00", VFP retrieves "˙ţW i n d o w s R e g i s t r y E d i t o r V e r s i o n 5 . 0 0", two funny charactes on the beginning and spaces between characters.
When the lines is [HKEY_CURRENT_USER\SOFTWARE\Native Instruments]", VFP retrievs" [ H K E Y _ C U R R E N T _ U S E R \ S O F T W A R E \ N a t i v e I n s t r u m e n t s ]", it put spaces. When I open this file in any text editor, everything looks fine. No funny characters, no spaces.
 
This line in PowerShell fixed the problem:
Get-Content "D:\input.reg" | Out-File "d:\output.reg" -Encoding ASCII
 

Part and Inventory Search

Sponsor

Back
Top