Dealing with Entries¶
Here, we are going to learn how to deal with registry entries by using “ring_wincreg” extension capabilities through RCRegistry class library.
Create Entry¶
We can create an empty entry using Create() function. This function accepts one parameter which is the type of entry to be created. If the entry is already existed this function will return error message.
Load "wincreg.ring"
Reg = New RCRegistry {
OpenKey([HKEY_CURRENT_USER, "Software\MyApp"])
}
Reg["NewValue"].Create(REG_BINARY)
Reg.CloseKey()
Note
Creating an empty entry with Create() function will initialize it with nil value of the corresponding data type.
Note
Default entry is considered not existed if it is still not set. So if we use Create() function it will be initialized with value of corresponding data type.
We can indirectly create any entry by using those functions that set the values for each data type.(Set Value) So that we can create any entry by initially setting any value to it as follow:
Load "wincreg.ring"
Reg = New RCRegistry {
OpenKey([HKEY_CURRENT_USER, "Software\MyApp"])
}
Reg["AppStyle"].SetValue("Normal Style")
Reg["AppOpenCount"].SetDWORD(3)
Reg.CloseKey()
Entry Existence¶
We can check whether a specific entry is existed or not using Exists() function as follow:
Load "wincreg.ring"
Reg = New RCRegistry {
OpenKey([HKEY_CURRENT_USER, "Software\MyApp"])
}
If Reg["AppStyle"].Exists() = True
See "AppStyle is existed in MyApp key"
Ok
Reg.CloseKey()
Get Entry¶
We can get one entry from any opened key, if it contains any, by using GetEntryAt() and GetEntryName() functions.
GetEntryAt() Function¶
This function will return a key handle by its index so that we can not deal with it as string with all other function but we can use GetEntryName() function to get it is string.
This function actually used in case that we want to transfer a whole entry containing its all properties within “ring_wincreg” extension from one key to attach it to another (ex. copy).
Load "wincreg.ring"
DestReg = New RCRegistry {
OpenKey([HKEY_CURRENT_USER, "Software\MyApp2"])
}
New RCRegistry {
OpenKey([HKEY_CURRENT_USER, "Software\MyApp"])
EntryH = GetEntryAt(1)
CopyTo(EntryH, DestReg.Key)
CloseKey()
}
DestReg.CloseKey()
GetEntryName() Function¶
This function is used to get the name of an entry handle that could be retrieved by GetEntryAt() function.
Load "wincreg.ring"
Reg = New RCRegistry {
OpenKey([HKEY_CURRENT_USER, "Software\MyApp"])
}
EntryH = Reg.GetEntryAt(1)
See "The retrieved entry name is : " + Reg.GetEntryName(EntryH)
Reg.CloseKey()
Entries Count¶
We may need to know the total number of values/entries within the opened key. This could be done by using EntriesCount() function.
Load "wincreg.ring"
Reg = New RCRegistry
Reg.OpenKey([HKEY_CURRENT_USER, "Software\MyApp"])
See "The total number of entries are : " + Reg.EntriesCount()
Reg.CloseKey()
Get All Entries¶
We can get a list of all entries contained in an opened key by using GetEntries() function as follow:
Load "wincreg.ring"
Reg = New RCRegistry {
OpenKey([HKEY_CURRENT_USER, "Software\MyApp"])
}
aList = Reg.GetEntries()
See "These are the entries that are contained in MyApp" + NL
See aList
Reg.CloseKey()
Access the default entry¶
We can access the default entry that is present in each key in the registry tree by passing empty string as an entry name
Load "wincreg.ring"
Reg = New RCRegistry { OpenKey([HKEY_CURRENT_USER, "Software\MyApp"]) }
See "Setting the default entry value >>> " + NL
Reg[""].SetValue("default entry value")
See "The value of default entry is : " + Reg[""].GetValue()
Reg.CloseKey()
Note
Default entry is of (REG_SZ) data type by default but it can take any data type by setting the value using the data type specific functions. (Set Value)
Copy Entries¶
We can copy an entry or the whole list of entries in an opened key to another key by using CopyTo() and CopyAllTo() functions.
CopyTo() Function¶
This function has two instances one can be used to copy an entry by passing its handle GetEntryAt() Function, the other is used to copy any entry by using its name.
Here is an example of the second instance of CopyTo() function.
Load "wincreg.ring"
Reg = New RCRegistry {
OpenKey([HKEY_CURRENT_USER, "Software\MyApp"])
}
DestReg = New RCRegistry {
OpenKey([HKEY_CURRENT_USER, "Software\MyApp2"])
}
Reg["AppVersion"].CopyTo(DestReg.Key)
See "The value of the copied AppVersion entry is : " + DestReg["AppVersion"].GetValue()
Reg.CloseKey()
DestReg.CloseKey()
CopyAllTo() Function¶
This function can copy all of the opened key entries to another one.
Load "wincreg.ring"
Reg = New RCRegistry { OpenKey([HKEY_CURRENT_USER, "Software\MyApp"]) }
DestReg = New RCRegistry { OpenKey([HKEY_CURRENT_USER, "Software\MyApp2"]) }
Reg.CopyAllTo(DestReg.Key)
See "The copied entries are : " + NL
See DestReg.GetEntries()
Reg.CloseKey()
DestReg.CloseKey()
Rename Entry¶
We can rename any entry by using Rename() function. The new name should be passed as a parameter to Rename() function.
Load "wincreg.ring"
Reg = New RCRegistry {
OpenKey([HKEY_CURRENT_USER, "Software\MyApp"])
}
Reg["AppStyle"].Rename("AppGeneralLook")
Reg.CloseKey()
Checking Entry Type¶
We can check a specific entry for it is type by some useful functions. These functions are:
- IsString() function : return True if the entry is of (REG_SZ) type.
- IsDWORD() function : return True if the entry is of (REG_DWORD) type.
- IsMultiString() function : return True if the entry is of (REG_MULTI_SZ) type.
- IsExpandSZ() function : return True if the entry is of (REG_EXPAND_SZ) type.
- IsQWORD() function : return True if the entry is of (REG_QWORD) type.
- IsBinary() function : return True if the entry is of (REG_BINARY) type.
Example:
Load "wincreg.ring"
Reg = New RCRegistry { OpenKey([HKEY_CURRENT_USER, "Software\MyApp"]) }
If Reg["AppPath"].IsString() = True
See Reg["AppPath"].GetValue()
Ok
Reg.CloseKey()
Get Entry Type¶
We can get the type of entry directly from registry by using Type() and TypeName() functions.
Type() Function¶
The registry entries types are known with specific numbers so that using Type() function will return a number of the type of the specified entry.
There are predefined Registry types constants in the “wincreg.rh” header file that may be used for comparison with this function return.
Example:
Load "wincreg.ring"
Reg = New RCRegistry { OpenKey([HKEY_CURRENT_USER, "Software\MyApp"]) }
If Reg["AppVersion"].Type() = REG_SZ
See "This (AppVersion) entry is of (REG_SZ) type"
Ok
Reg.CloseKey()
TypeName() Function¶
This function return the type name of a specified entry as a string.
Load "wincreg.ring"
Reg = New RCRegistry { OpenKey([HKEY_CURRENT_USER, "Software\MyApp"]) }
See "The type of (AppVersion) entry is : " + Reg["AppVersion"].TypeName()
Reg.CloseKey()
Clear Entry¶
We can clear the content of any data type entry by using Clear() function as follow:
Load "wincreg.ring"
Reg = New RCRegistry { OpenKey([HKEY_CURRENT_USER, "Software\MyApp"]) }
See "The old logo is : " + Reg["AppLogo"].GetValue() + NL
Reg["AppLogo"].Clear()
Reg["AppLogo"].SetValue("We are in your eye's TRUST")
See "The new logo is : " + Reg["AppLogo"].GetValue()
Reg.CloseKey()
Delete Entry¶
We can delete any entry that is not needed by using Delete() function as follow:
Load "wincreg.ring"
Reg = New RCRegistry { OpenKey([HKEY_CURRENT_USER, "Software\MyApp"]) }
Reg["NewEntry"].Create(REG_SZ)
See "NewEntry has been created" + NL
Reg["NewEntry"].Delete()
See "NewEntry has been deleted"
Reg.CloseKey()
Note
We can use this function with default entry to clear its content and restore its default data type (REG_SZ).