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

Updating Windows Registry using VFP

Status
Not open for further replies.

stanlyn

Programmer
Sep 3, 2003
945
US
Hi,

Where is the documentation for registry reads, writes and otherwise total registry mods? I've been trying to get vfp's ffc registry.vcx to work without success and am finding very little usage documentation. The .h file doesn't help either. So the question is, "Where is good docs with example code" on its usage? Oh, the VFP help file has nothing for functions like IsKey(), or any of the others...

Below is a paste of my Sandbox...

Thanks, Stanley

Code:
#Define HKEY_CLASSES_ROOT           -2147483648  && BITSET(0,31)
#Define HKEY_CURRENT_USER           -2147483647  && BITSET(0,31)+1
#Define HKEY_LOCAL_MACHINE          -2147483646  && BITSET(0,31)+2
#Define HKEY_USERS                  -2147483645  && BITSET(0,31)+3

lcPath = 'Software\MyNewHopefullyUniqueKey\123456\I_HOPE_YOU_NAMED_THIS'

#UnDef _PATH
#Define _PATH (lcPath)

Public oRegistry
SET CLASSLIB TO "d:\licgen\licgen_2015\classes\registry.vcx"
#include REGISTRY.H

oRegistry = Newobject("registry", "registry.vcx")
*oRegistry = Newobject("registry", Home() + "ffc\registry.vcx")

*.CloseKey()
*.DeleteKey
*.DeleteKeyValue

*=GetRegKey('DbcName', @cValue, Path, HKEY_CURRENT_USER)
*?zz

*!*		aa= oRegistry.GetKeyValue(Path, HKEY_CURRENT_USER)
*!*		?aa
*!*	lcResource=oRegistry.getRegKey('resourceTo', @lcResource, Path', HKEY_CURRENT_USER)

*!*	MessageBox("My resourcefile is named: "+lcResource)
*!*		
*!*		
*!*		
*!*		bb= oRegistry.GetRegKey(Path, HKEY_CURRENT_USER)
*!*		?bb
*!*		cc= oRegistry.IsKey(Path, HKEY_CURRENT_USER)
*!*		?cc

llIsThere=oRegistry.IsKey(_PATH, HKEY_CURRENT_USER)

IF llIsThere
    MessageBox("NjSrv020.Kamrat is installed")
ELSE
    MessageBox("NjSrv020.Kamrat is not installed")
        RETURN
ENDIF

	*.OpenKey
	*.SetKeyValue
	*.SetRegKey

Release oRegistry
return


If oRegistry.OpenKey("Software\MyNew2HopefullyUniqueKey\123456", HKEY_CURRENT_USER, .T.) = 0

	*SET STEP on
	=oRegistry.CloseKey()

	If oRegistry.setregkey("I_HOPE_YOU_NAMED_THIS", ;
			"somthis", ;
			"Software\MyNew1HopefullyUniqueKey\123456\", ;
			HKEY_CURRENT_USER) != 0

		Messagebox("Sorry error setting the registry value!", 48)
		Return
	Endif

	Messagebox("Regedit will run while I wait for you to go see your new value" + ;
		CHR(13) + "Look under the HKEY_CURRENT_USER hive and click on the Software key..." +;
		CHR(13) + "then click on MyNewHopefullyUniqueKey key and look to the right and you should see " +;
		"I_HOPE_YOU_DONT_HAVE_A_VALUE_NAMED_THIS")

	Run /N regedit

	Messagebox("Are you done looking and want me to delete it?")

	*!*		If oRegistry.DeleteKeyValue("I_HOPE_YOU_DONT_HAVE_A_VALUE_NAMED_THIS", ;
	*!*				"Software\MyNewHopefullyUniqueKey\123456\", ;
	*!*				HKEY_CURRENT_USER) != 0
	*!*			Messagebox("Sorry error deleting the registry value I_HOPE_YOU_DONT_HAVE_A_VALUE_NAMED_THIS!",48)
	*!*			Return
	*!*		Endif

	*!*		Messagebox("Now that we've deteleted the value, lets delete the 2 new keys")

	*!*		If oRegistry.DeleteKey(HKEY_CURRENT_USER,"Software\MyNewHopefullyUniqueKey\123456") != 0
	*!*			Messagebox("Sorry error deleting the registry key 123456!",48)
	*!*		Else
	*!*			If oRegistry.DeleteKey(HKEY_CURRENT_USER,"Software\MyNewHopefullyUniqueKey") != 0
	*!*				Messagebox("Sorry error deleting the registry key MyNewHopefullyUniqueKey!",48)
	*!*			Endif
	*!*			Return
	*!*		Endif
Else
	Messagebox("We weren't able to create and open the new key",48)
Endif


***********************************


Local loregistry, sValue, sPath
sValue = ''
sPath = HOME(1) + 'FFC\registry.vcx'
SET CLASSLIB TO (sPath)
#DEFINE HKEY_LOCAL_MACHINE          -2147483646  && BITSET(0,31)+2
loregistry = NEWOBJECT('registry')
IF loregistry.OpenKey('Software\Mycompany123\Myproject123', HKEY_LOCAL_MACHINE,.T.) = 0
    IF loregistry.GetKeyValue('datapath',@sValue) != 0
        sValue =ADDBS(GetShortPath(Alltrim(GETDIR(sValue, 'Locate Myproject123 Data.', 'Browse For Folder'))))
        IF loregistry.SetRegKey('datapath', sValue, 'Software\Mycompany123\Myproject123', HKEY_LOCAL_MACHINE) != 0
        MESSAGEBOX('datapath was unable to be set!', 16, 'Error...')
        RETURN
        ENDIF
    ENDIF
ENDIF
=loregistry.CloseKey()
IF MESSAGEBOX('Do you wish to delete the registry entries you have just made?',36, 'Delete?') = 6
        IF loregistry.DeleteKeyValue('datapath', 'Software\Mycompany123\Myproject123', HKEY_LOCAL_MACHINE) = 0
            IF loregistry.DeleteKey(HKEY_LOCAL_MACHINE, 'Software\Mycompany123\Myproject123') = 0
                IF loregistry.DeleteKey(HKEY_LOCAL_MACHINE, 'Software\Mycompany123') != 0
                    MESSAGEBOX('Unable to delete entries!', 16, 'Error...')        
                ENDIF
            ELSE
                MESSAGEBOX('Unable to delete entries!', 16, 'Error...')        
            ENDIF
        ELSE
            MESSAGEBOX('Unable to delete entries!', 16, 'Error...')        
        ENDIF
endif

Function GetShortPath
* Turn the path into a dos path
* so that paths still work with macro substitution
    Parameters sFileName
    Local nRes, sPath

    Declare Integer GetShortPathNameA In Win32API As GetShortPathName String, String, Integer

    **Create a buffer
    sPath = Replicate(Chr(32), 165) + Chr(0)
    **retrieve the short pathname
    nRes= GetShortPathName(sFileName, @sPath, 164)

    Clear Dlls GetShortPathName

    **remove all unnecessary chr$(0)'s and send it back
    Return (Left(sPath, nRes))
Endfunc
 
Stanley,

many things have changed since Vista, eg registry virtualisation, 32bit and 64bit registry besides user and system registry, which were also present in the past.

Nothing of the new changes is reflected in the ffc registry.vcx, but that class is documented in the VFP help as any ffc class is for the situation at the time being.
Search for "Registry Access Foundation Class"

Either you write your own library from scratch by looking at MSDN documentation or you look for something else, eg another registry library or even not using the registry, unless you need to address some keys from Windows itself or other software. But actually that's a thing for administration or setup, not within an application. Using .reg files is one way to merge in keys, for example. That'll depend on user privileges, but you depend on them anyway.

There are lots of infos about registry virtualisation, UAC and other things at the MS site.
Here's a starting point for the most current registry documentation:

Bye, Olaf.
 
Or use wscript from within VFP for reading and writing the registry.

example

Code:
WSHShell = CreateObject("WScript.Shell")
 
WSHShell.RegWrite("HKCU\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\example.exe", 11001, "REG_DWORD")

res=WSHShell.RegRead("HKCU\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\example.exe")
? res


There is also a RegDelete function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top