Method: Key::WriteKeyRegistry
WriteKeyRegistry(Hive, KeyName, ValueName)
The
WriteKeyRegistry method writes the current value of the key to a given location in the registry.
Hive
The
Hive argument is an enumerated constant, which defines the following five hexidecimal values:
| HKeyClassesRoot |
= |
0x80000000 |
| HKeyCurrentUser |
= |
0x80000001 |
| HKeyLocalMachine |
= |
0x80000002 |
| HKeyUsers |
= |
0x80000003 |
| HKeyCurrentConfig |
= |
0x80000005 |
As the name of the argument suggests, each of these values corresponds to a particular hive within
the registry.
On Win32 platforms, the registry is a hierarchically structured database which contains
information pertinent
to the configuration of both the operating system and the software installed on the machine. This database
is conceptually organized as a tree, with each node under the root indicating a major division of
the database.
The hives represent these immediate children of the registry root node, and provide the base for
the pathnames
of any subkeys that lie under them.
KeyName
The
KeyName argument is the name of the registry subkey which will contain the cipher key value. This name takes the form of a pathname,
with the sections of the name representing subkeys, rather than folders. Thus, the name "SOFTWARE\OurStuff"
indicates the "OurStuff" subkey, which is a child of the "SOFTWARE" subkey, which is, in turn,
the child of a hive node within the registry.
If the subkey specified by the
KeyName argument does not exist, it will
be created.
ValueName
The
ValueName argument indicates the name of the value that will hold the cipher key data.
Each key in the registry contains zero or more
values, which actually hold the data relavent to the subkey that owns them. The value whose name is given
by the
ValueName argument, then, will be placed under the subkey indicated by the
KeyName
argument, and will contain the cipher key stored within the
Key object for which
the
WriteKeyRegistry method is called.
Note that if the value does not exist, it will be created, while any existing value
will be overwritten.
Example:
Private Sub Command1_Click()
Dim intLength As Integer
Dim strValueName as String
Dim objKey As DGENCRYPTLib.Key
Select Case Combo1.ListIndex
Case -1
MsgBox "please select a key length"
Exit Sub
Case 0
intLength = 16
Case 1
intLength = 24
Case 2
intLength = 32
End Select
strValueName = Text1.Text
If strValueName = "" Then
MsgBox "please enter a name for the key"
Exit Sub
End If
Set objKey = New DGENCRYPTLib.Key
objKey.GenerateKey intLength
On Error Resume Next
objKey.WriteKeyRegistry HKeyLocalMachine, "SOFTWARE\OurStuff\WebKeys", strValueName
If Err.Number <> 0 Then
Dim strMessage As String
strMessage = "an error occurred while writing the new key value:" & vbCrLf & _
"Source: " & Err.Source & vbCrLf & _
"Code: " & Err.Number & vbCrLf & _
"Description: " & Err.Description & vbCrLf
MsgBox strMessage, vbExclamation
Else
MsgBox "the new key value has been placed in the registry"
End If
On Error GoTo 0
Set objKey = Nothing
End Sub