Reading and Writing Windows Registry Entries from the 4GL

Chris Kelleher

Administrator
Staff member
<BLOCKQUOTE><font size="1" face="Arial, Verdana">code:</font><HR><pre>FUNCTION FuncRegVal RETURNS CHARACTER
( pBaseKey as char, /* i.e. "HKEY_..." */
pKeyName as char, /* main key, i.e. "software\ACME..." */
pSecName as char, /* section */
pItem as char /* item identifier, "" = return list, ? = default */
) :
/*--------------------------------------------------------------------------
----
Purpose: Read a value from any section of the registry
Notes: Windows only
----------------------------------------------------------------------------
--*/
def var iValue as char no-undo.

load pKeyName
base-key pBaseKey no-error.

if not error-status:error then
do:
use pKeyName.
if pItem = ? then
get-key-value section pSecName
key default
value iValue.
else
get-key-value section pSecName
key pItem
value iValue.
if iValue = ? then
iValue = "".
unload pKeyName no-error.
end. /* if no error*/

return iValue.

END FUNCTION.

/* RegWrite -- write a value to any section of the registry */
procedure RegWrite:
def input parameter pBaseKey as char. /* i.e. "HKEY_..." */
def input parameter pKeyName as char. /* main key, i.e. "software\ACME..."
*/
def input parameter pSecName as char. /* section */
def input parameter pItem as char. /* item identifier, ? = default, ""
= delete key */
def input parameter pValue as char. /* value to store; ? = delete */

load pKeyName
base-key pBaseKey no-error.

/* create new if it did not exist */
if error-status:error then
load pKeyName new
base-key pBaseKey no-error.

if not error-status:error then
do:
use pKeyName.
if pItem = ? then
put-key-value section pSecName
key default
value pValue.
else
put-key-value section pSecName
key pItem
value pValue.

unload pKeyName no-error.
end. /* if */
return.
end procedure.

message
FuncRegVal("HKEY_LOCAL_MACHINE",
"Software\Microsoft\Windows",
"CurrentVersion",
"Version")
view-as alert-box.[/code]
 
Top