Rapid-Q Documentation by William Yu (c)1999,    corrected  by Jacques Philippe Appendix A: QREGISTRY

QREGISTRY Component

QRegistry encapsulates functions that operate on the Window's system registry. The Registry is composed of Keys and SubKeys. Each Key and SubKey can contain one or more variables named Values. These values have a ValueName and a ValueData

QRegistry Properties
FieldTypeR/WDefault




CurrentKeyINTEGERR
CurrentPathSTRINGR
GetDataSize(ValueName$)INTEGERR
GetDataType(ValueName$)INTEGERR
HasSubKeysINTEGERR
KeyItemCountINTEGERR
ValueItemCountINTEGERR
RootKeyINTEGERRWHKEY_CURRENT_USER

QRegistry Methods
MethodTypeDescriptionParams




CloseKeySUBCloses opened key0
CreateKeyFUNCTION (Key$) AS INTEGERCreates a new key in CurrentPath.1
DeleteKeyFUNCTION (Key$) AS INTEGERDeletes key.1
DeleteValueFUNCTION (ValName$) AS INTEGERDeletes a value data.1
KeyExistsFUNCTION (Key$) AS INTEGERReturns 0 or 1 if key exists.1
KeyItemFUNCTION (Index%) AS STRINGRetrieve the names of the subkeys1
MoveKeyFUNCTION (OldKey$, NewKey$, Delete%)Moves existing key, subkeys, and data values.3
OpenKeyFUNCTION (Key$, CanCreate%)CanCreate specifies whether to create the specified key if it does not exist.2
ReadBinary(*)FUNCTION (ValueName$, Index%) AS BYTEReturn binary value of specified key(Bug : Index must Start at -1)2
ReadFloatFUNCTION (ValueName$) AS DOUBLEReturn double value of specified key1
ReadIntegerFUNCTION (ValueName$) AS INTEGERReturn integer value of specified key1
ReadStringFUNCTION (ValueName$) AS STRINGReturn string value of specified key1
RegistryConnectFUNCTION (CompName$) AS INTEGEREstablishes connection to another computer's registry.1
RenameValue(*)SUB (OldValueName$, NewValueName$)Renames existing data value.2
ValueExistsFUNCTION (ValueName$) AS INTEGERReturns 0 or 1 if data value Value$ exists.1
ValueItemFUNCTION (Index%) AS STRINGRetrieve the names of the data values1
WriteBinary(*)SUB (ValueName$, BYTE(), Size%)Write Array of BYTEs in the specified key3
WriteFloat(*)SUB (ValeName$, ValueData#)Write double value in the specified key2
WriteInteger(*)SUB (ValueName$, ValueData&)Write integer value in the specified key2
WriteString(*)SUB (ValueName$, ValueData$)Write string in the specified key2
Notes (*):
- READ and WRITE requires the mother KEY to be OPENED first with OpenKey(Key)
- WRITE subs Create ValueName if it does not exist
- MOVEKEY sets undefined ValueDatas of String type to "", which can be a problem.
- MOVEKEY with Delete% set to one is like renaming a key.

Common Windows registry constants are
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_PERFORMANCE_DATA = &H80000004
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006

HKEY_CLASSES_ROOT - contains file association mappings for drag-and-drop, OLE, shortcuts, Win UI core aspects
HKEY_CURRENT_USER - section of HKEY_USERS for the current logged in user for logon names, desktop and Start menu settings.
HKEY_LOCAL_MACHINE - For all users, computer hardware, software, and other preferences info.
HKEY_USERS - each users individual preferences-- represented by a SID sub-key located under the main branch.
HKEY_CURRENT_CONFIG - section of HKEY_LOCAL_MACHINE appropriate for the current hardware configuration.
QRegistry Events
EventTypeOccurs when...Params





QRegistry Examples
Example : 
Key HKEY_CLASSES_ROOT .Bas\Shell\Open\Command 
contains a Default value who's ValueName is "" and whose value is "C:\Rapidq\RapidQ.Exe %1" 
ValueName maybe "AnyName". The default ValueName is "" .
The Registry can be edited with Regedit.Exe or regedt32.Exe.


Example 2

'  Detect if your computer is connected to the internet
Const HKEY_LOCAL_MACHINE = &H80000002
DIM Registry AS QRegistry

Registry.RootKey = HKEY_LOCAL_MACHINE
Registry.OpenKey("System\CurrentControlSet\Services\RemoteAccess", 0)

'(index was 0 originally, but due to ReadBinary bug it must be -1)
IF Registry.ReadBinary("Remote Connection", -1) = 1 THEN
  ShowMessage("You're connected!")
ELSE
  ShowMessage("You're not connected!")
END IF
Registry.CloseKey

' ---- EXAMPLE 2 by Jacques Phillipe -----------------
Const HKEY_CURRENT_USER  = &H80000001
'
DIM Registry AS QRegistry

With Registry
   .RootKey = HKEY_CURRENT_USER
'  Write Key and Values
'  --------------------
   .OpenKey("TestToDelete", 1)   ' Create Key if dont exist
        .WriteInteger("MyInteger", 1234567890)
        .WriteString ("Mystring", "1234567890")
        DefByte MyBinary(10) = {1,2,3,4,5,6,7,8,9,0}
        .WriteBinary ("MyBinary", MyBinary(), 10)
   .CloseKey
'  Read Values
'  -----------
   .OpenKey("TestToDelete", 1)
        Print "MyInteger=";.ReadInteger("MyInteger")
        Print " Mystring=";.ReadString ("Mystring")
        DefInt N
        For N = -1 To 8  ' This is a QREGISTRY 'bug' Binary index starts at -1
            Print "MyBinary(";N")=";.ReadBinary ("MyBinary", N)
        Next N
   .CloseKey
'  Delete the Key and all its Values
' ----------------------------------
   .DeleteKey ("TestToDelete")
End With
' Exit Console
' ------------
DefStr sExit
Input "    FINISHED               CR to QUIT ", sExit
Application.Terminate
' -------------------------------------

Prev Component Contents Next Component