VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsRegistry"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'=========================================
'=          Easy Emailer 2.4             =
'=---------------------------------------=
'=  Developed by P. G. B. Prasanna       =
'=  A Software Developer from Sri Lanka  =
'=  E-mail: pgbsoft@gmail.com            =
'=---------------------------------------=
'=        Copyright © 2015 PGBSoft       =
'=           All rights reserved         =
'=========================================

'Class Module for registry operations.

Option Explicit

Private Declare Function RegDeleteKey _
    Lib "advapi32.dll" Alias "RegDeleteKeyA" ( _
    ByVal hkey As Long, _
    ByVal lpSubKey As String) As Long
    
Private Declare Function SHDeleteKey _
    Lib "shlwapi.dll" Alias "SHDeleteKeyA" ( _
    ByVal hkey As Long, _
    ByVal pszSubKey As String) As Long
    
'Reg Key ROOT Types...
Private Const HKCU = &H80000001
Private Const HKLM = &H80000002
Private Const HKCR = &H80000000
Private Const HKU = &H80000003

Private Const ERROR_SUCCESS = 0&

Private objReg As Object

Private Sub Class_Initialize()
   Set objReg = CreateObject("Wscript.Shell")
End Sub

'Read Registry Value.
Public Function ReadRegData(ByVal strRLoc As String) As Variant

    On Error Resume Next
    ReadRegData = "": ReadRegData = objReg.RegRead(strRLoc)
    
End Function

'Set Registry Value.
Public Sub SetRegData(ByVal strRLoc As String, ByVal varData As Variant, Optional intValueType As Integer = 0)

    On Error Resume Next
    
    With objReg
        Select Case intValueType
            Case 0: .RegWrite (strRLoc), varData, "REG_DWORD"
            Case Else: .RegWrite (strRLoc), varData
        End Select
    End With
    
End Sub

'Delete Registry Value.
Public Sub RemoveRegData(ByVal strRLoc As String)

    On Error Resume Next
    objReg.RegDelete (strRLoc)
    
End Sub

'Remove registry keys with values.
Public Function RemoveRegKey(ByVal intKeyRootOpt As Integer, ByVal strKeyPath As String) As Boolean

    Dim lKey As Long, KeyRoot As Long
    RemoveRegKey = False
    
    Select Case intKeyRootOpt
        Case 1: KeyRoot = HKCU
        Case 2: KeyRoot = HKLM
        Case 3: KeyRoot = HKCR
        Case 4: KeyRoot = HKU
    End Select
    
    lKey = RegDeleteKey(KeyRoot, strKeyPath)
    
    If lKey <> ERROR_SUCCESS Then
        lKey = SHDeleteKey(KeyRoot, strKeyPath)
        If Not lKey <> ERROR_SUCCESS Then RemoveRegKey = True
    Else
        RemoveRegKey = True
    End If
    
End Function

'Get all the registry value names in a specified key.
Public Function GetRegValues(ByVal intKeyRootOpt As Integer, strKeyPath As String) As Variant

    On Error GoTo Err
    
    Dim strComputer As String
    Dim objRegEnum As Object
    Dim arrValueNames As Variant
    Dim arrValueTypes As String
    Dim lngKeyRoot As Long
    
    Select Case intKeyRootOpt
        Case 1: lngKeyRoot = HKCU
        Case 2: lngKeyRoot = HKLM
        Case 3: lngKeyRoot = HKCR
        Case 4: lngKeyRoot = HKU
    End Select
    
    strComputer = "."
    Set objRegEnum = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
                     strComputer & "\root\default:StdRegProv")

    objRegEnum.EnumValues lngKeyRoot, strKeyPath, arrValueNames, arrValueTypes

    GetRegValues = arrValueNames

Exit Function

Err:
    GetRegValues = Null
    
End Function

Private Sub Class_Terminate()
   Set objReg = Nothing
End Sub
