Managing information in the Windows registry
Functions for accessing the Registry
PowerBuilder provides several functions you can use to manage
application settings in the Windows registry:
Function | Description |
---|---|
RegistryDelete | Deletes a key or a value in a key in the Windows registry. |
RegistryGet | Gets a value from the Windows registry. |
RegistryKeys | Obtains a list of the keys that are child items (subkeys) one level below a key in the Windows registry. |
RegistrySet | Sets the value for a key and value name in the Windows registry. If the key or value name does not exist, RegistrySet creates a new key or value name. |
RegistryValues | Obtains a list of named values associated with a key. |
For the complete information for these functions,
see the PowerScript Reference
.
Overriding initialization files On Windows you can use the ProfileString functions to obtain
information from the registry instead of from an initialization
file. On Windows NT, create a new folder called INIFILEMAPPING at
the following location:
1 |
hkey_current_usersoftwaremicrosoftwindows ntcurrent version |
To override the WIN.INI file, create a key in the new folder
called WIN.INI with the following value:
1 |
#usr:softwaremicrosoftwindows ntcurrent |
1 |
versionextensions |
On Windows 95 and 98, substitute windows for windows
nt in both paths.
Support for multiple platforms
Both Windows 95 and Windows NT use a system registry for application settings,
but UNIX does not. Therefore, don’t use any of the functions
that access the Windows registry if you are building a cross-platform
application.
The examples below use the registry to keep track of database
connection parameters. The connection parameters are maintained
in the registry in the MyCoMyAppdatabase
branch
under HKEY_CURRENT_USERSoftware
:
Reading values from the registry
The following script retrieves values for the default Transaction
object from the registry.
1 |
RegistryGet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"dbms", sqlca.DBMS) |
1 |
RegistryGet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"database", sqlca.database) |
1 |
RegistryGet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"userid", sqlca.userid) |
1 |
RegistryGet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"dbpass", sqlca.dbpass) |
1 |
RegistryGet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"logid", sqlca.logid) |
1 |
RegistryGet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"logpass", sqlca.logpass) |
1 |
RegistryGet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"servername", sqlca.servername) |
1 |
RegistryGet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"dbparm", sqlca.dbparm) |
Setting values in the registry
The following script stores the values for the Transaction
object in the registry:
1 |
RegistrySet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"dbms", sqlca.DBMS) |
1 |
RegistrySet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"database", sqlca.database) |
1 |
RegistrySet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"userid", sqlca.userid) |
1 |
RegistrySet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"dbpass", sqlca.dbpass) |
1 |
RegistrySet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"logid", sqlca.logid) |
1 |
RegistrySet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"logpass", sqlca.logpass) |
1 |
RegistrySet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"servername", sqlca.servername) |
1 |
RegistrySet & |
1 |
("HKEY_CURRENT_USERSoftwareMyCoMyAppdatabase", & |
1 |
"dbparm", sqlca.dbparm) |