*********************************************** DEFINE CLASS RegistryInterface as CUSTOM *********************************************** *!* Usage examples.. *!* Instantiate.. *!* test = NEWOBJECT("registryInterface","registryinterface.prg") *!* RETURN value of reg_SZ 'Sender' in HKLM\software\Public Domain\Blat\ *!* ?test.check_registry_value("Sender","software\Public Domain\Blat") *!* returns value or a 'KGNOsomething' error code *!* SET value of reg_SZ 'Sender' to "bkuhn@examinetics.com" in HKLM\software\Public Domain\Blat\ *!* NOTE: This will create the entire key if it doesn't exist *!* test.set_registry_value("Sender","bkuhn@examinetics.com","software\Public Domain\Blat") *!* returns .T. (success) or .F. #if .f. LOCAL this as RegistryInterface OF registryinterface.prg #endif icProgramRegistryKey = '' && this is the registry path under HKLM i.e. "software\microsoft\Office\Word" inHKEY_LOCAL_MACHINE = -2147483646 && -2147483646 is HKEY_LOCAL_MACHINE inHKEY_CLASSES_ROOT = -2147483648 inHKEY_CURRENT_USER = -2147483647 inHKEY_USERS = -2147483645 inCurrent_Key = 0 oReg = .NULL. ********************************** FUNCTION INIT ********************************** this.inCurrent_Key = this.inHKEY_LOCAL_MACHINE && specify numeric key for something else if you need.. this.oReg = NEWOBJECT('registry','registry.vcx') RETURN && INIT ********************************** ENDFUNC && INIT ********************************** ********************************** FUNCTION set_registry_value ********************************** *!* this function sets the value of this.inCurrent_Key\pcKey\pcRegistryValueName PARAMETERS pcRegistryValueName,pcNewValue,pcKey local llRetVal local lcValue llRetVal = .F. && default return value lcvalue = SPACE(260) IF !(this.oReg.IsKey(pcKey,this.incurrent_Key)) && is there a key at all? this.oReg.Openkey(pcKey, this.inCurrent_Key, .T.) && create the key endif this.oReg.Openkey(pcKey, this.inCurrent_Key, .F.) IF this.oReg.SetKeyValue(pcRegistryValueName,pcNewValue) <>0 && set the new value *!* MESSAGEBOX('Unable to set registry value '+pcRegistryValueName) ELSE llRetVal = .T. endif this.oReg.Closekey() RETURN llRetVal && set_registry_value ********************************** ENDFUNC && set_registry_value ********************************** ********************************** FUNCTION Check_Registry_Value ********************************** *!* this function returns value of this.inCurrent_key\pcKey\pcValueToCheck PARAMETERS pcValueToCheck,pcKey local llRetVal local lcValue IF EMPTY(pcValueToCheck) RETURN 'KGNOVALUETOCHECK' ELSE pcValueToCheck=TRIM(pcValueToCheck) ENDIF IF EMPTY(pcKey) RETURN 'KGNOKEYSPECIFIED' ELSE pcKey=TRIM(pcKey) endif llRetVal = .F. && default return value - DebugMode is OFF lcvalue = SPACE(260) IF INLIST(LEFT(pcKey,1),'\','/') pcKey = substr(pcKey,2) ENDIF IF INLIST(right(pcKey,1),'\','/') pcKey = substr(pcKey,1,LEN(pcKey)-1) ENDIF IF !(this.oReg.IsKey(pcKey,this.inCurrent_Key)) && is there a key at all? lcValue='KGNOKEYFOUND' *!* this.oReg.Openkey(pcKey, lnHKEY_LOCAL_MACHINE, .T.) && create the key ELSE this.oReg.Openkey(pcKey, this.inCurrent_Key, .F.) IF this.oReg.GetKeyValue(pcValueToCheck,@lcValue) <> 0 && failed to check value lcValue='KGNOVALUEFOUND' endif endif this.oReg.Closekey() RETURN TRIM(lcValue) && check_registry_value ********************************** ENDFUNC && check_registry_value ********************************** *********************************************** ENDDEFINE && registryinterface ***********************************************