Hi,
Windows registry keep program information how to start and where to start.
Aprat from that it stores some information related to that program
Here is a class that u can user to access registry
Imports Microsoft.Win32
Public Class Registries
' TODO : Complete registry class------completed
' Using the class
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'if just the keyname is passed to one of the constructors then the class will
' return keyvalue through its "keyvalue" properties
' if both keyname and keyvalue is passed as arg to one of the overloaded constructor
' then the class will create a key if it does not exist and assign the key the value
' under the key hive localmachine\software\myApp
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#Region " Variables "
Dim m_SubKey As String = "myApp" ' name of the key to be created under HKLM\Software---
' Will be name of the back office system
Dim m_KeyValue As String ' will hold the value of the registry key passed as an arg to one of the constructor
#End Region
#Region " Properties "
Public ReadOnly Property KeyValue() As String
Get
Return m_KeyValue
End Get
End Property
#End Region
#Region " Constructors "
Public Sub New(ByVal keyname As String)
' contructor used to return the value of the key passed
Call ReturnKeyValue(keyname)
End Sub
Public Sub New(ByVal KeyName As String, ByVal keyValue As String)
' input parameters
' keyname : name of the key to be created under the software\focus
Call Createkey(KeyName, keyValue)
End Sub
Public Sub New(ByVal SubKey As String, ByVal keyName As String, ByVal keyValue As String)
m_SubKey = SubKey
Call Createkey(keyName, keyValue)
End Sub
#End Region
#Region " Methods "
Private Sub Createkey(ByVal keyName As String, ByVal keyValue As String)
Dim regKey As RegistryKey
Dim iFoundKey As Int32 = -1
Dim arrKeyNames() As String
' find whether the key Focus exists
' if it does not exists then create one
regKey = Registry.LocalMachine.OpenSubKey("Software", True)
' check for existence of the key 'myApp' under the key 'Software'
arrKeyNames = regKey.GetSubKeyNames()
iFoundKey = System.Array.IndexOf(arrKeyNames, "myApp")
If iFoundKey = -1 Then
Try
regKey.CreateSubKey(m_SubKey) ' create the name of the software(Focus) as a sub key under HKLM\Software key
regKey.Close()
Catch ex As Exception
RecordError.WriteErr(ex.Message)
regKey.Close()
Return
End Try
End If
' Do the same for the keyname
regKey = Registry.LocalMachine.OpenSubKey("Software\" & m_SubKey, True)
arrKeyNames = regKey.GetSubKeyNames
iFoundKey = -1
iFoundKey = System.Array.IndexOf(arrKeyNames, keyName)
If iFoundKey = -1 Then ' key not found , create the key
Try
regKey.CreateSubKey(keyName) ' create the sub key under the Focus sub key
regKey.SetValue(keyName, keyValue)
regKey.Close()
Return
Catch ex As Exception
RecordError.WriteErr(ex.Message)
End Try
End If
Try
regKey.SetValue(keyName, keyValue)
Catch ex As Exception
Finally
regKey.Close()
End Try
End Sub
Private Sub ReturnKeyValue(ByVal keyname As String)
Try
Dim regKey As RegistryKey
regKey = Registry.LocalMachine.OpenSubKey("Software\myApp")
m_KeyValue = regKey.GetValue(keyname)
Catch ex As Exception
m_KeyValue = ""
End Try
End Sub
#End Region
End Class
You can create registry key like
Dim ReadRegistry As Registries
ReadRegistry = New Registries("LocalDatabase")
To access value
Databasestring= ReadRegistry.KeyValue