|
Imports Microsoft.Win32
Public Class Reg
Public ReadOnly Property HKLM() As RegistryKey
Get
Return Registry.LocalMachine
End Get
End Property
Public ReadOnly Property AppReg() As RegistryKey
Get
Return Registry.LocalMachine.OpenSubKey("Software\RDPMan", RegistryKeyPermissionCheck.ReadWriteSubTree)
End Get
End Property
Public Function CreateSubKey(ByVal ParentKey As RegistryKey, ByVal SubKey As String) As Boolean
Try
ParentKey.CreateSubKey(SubKey)
Return True
Catch e As Exception
Return False
End Try
End Function
Public Function DeleteSubKey(ByVal ParentKey As RegistryKey, ByVal SubKey As String) As Boolean
Try
ParentKey.DeleteSubKey(SubKey, False)
Return True
Catch e As Exception
Return False
End Try
End Function
Public Function WriteValue(ByVal ParentKey As RegistryKey, _
ByVal SubKey As String, _
ByVal ValueName As String, _
ByVal Value As Object) As Boolean
Dim Key As RegistryKey
Try
Key = ParentKey.OpenSubKey(SubKey, True)
If Key Is Nothing Then 'when subkey doesn't exist create it
Key = ParentKey.CreateSubKey(SubKey)
End If
'Once we have a handle to the key, set the value(the data)
Key.SetValue(ValueName, Value)
Return True
Catch e As Exception
Return False
End Try
End Function
Public Function ReadValue(ByVal ParentKey As RegistryKey, _
ByVal SubKey As String, _
ByVal ValueName As String, _
ByRef Value As Object) As Boolean
Dim Key As RegistryKey
Try
'open the given subkey
Key = ParentKey.OpenSubKey(SubKey, True)
If Key Is Nothing Then 'when the key doesn't exist throw an
'exception
Throw New Exception("the subkey doens't exist")
End If
'Get the value
Value = Key.GetValue(ValueName)
Return True
Catch e As Exception
Return False
End Try
End Function
Public Function GetSubKeys(ByVal ParentKey As RegistryKey, Optional ByVal SubKey As String = Nothing) As String()
If SubKey = Nothing Then
ParentKey = ParentKey
Else
Try
ParentKey = ParentKey.OpenSubKey(SubKey, True)
Catch ex As Exception
End Try
End If
Try
Return ParentKey.GetSubKeyNames()
Catch e As Exception
Return Nothing
End Try
End Function
Public Function DeleteValue(ByVal ParentKey As RegistryKey, _
ByVal SubKey As String, _
ByVal ValueName As String) As Boolean
Dim Key As RegistryKey
Try
'open the given subkey
Key = ParentKey.OpenSubKey(SubKey, True)
'when the key exists then delete the value
If Not Key Is Nothing Then
Key.DeleteValue(ValueName)
Return True
Else
Return False
End If
Catch e As Exception
Return False
End Try
End Function
End Class
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.