-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmRegistryV1.bas
122 lines (100 loc) · 3.85 KB
/
mRegistryV1.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Attribute VB_Name = "mRegistry"
'// Provides registry code.
'// Copyright (c)2002 Richard Holyoak.
'// Contact rholyoak@bigfoot.com
'// Requires RegistrationDatabase V1
Option Explicit
Public RegistryError As Integer
Private Const mstrVendor As String = "Software\Richard Holyoak\"
'// Registry keys
Public Const REG_OPTIONS As String = "Options"
Public Const REG_SETTINGS As String = "Settings"
Private Const ERROR_SUCCESS = 0&
Private Const ERROR_MORE_DATA = 234
Private Const ERROR_NO_MORE_ITEMS = 259
Public Sub RegPut(Section As String, Key As String, vSetting As Variant, lValueType As Long)
On Error Resume Next
'If App.ProductName = "" Then MsgBox "Error: No Product Name for this project!", vbCritical, "GetReg()": End
Dim hKey As Long
RegistryError = ERROR_NONE
Select Case Section
Case ""
hKey = HKEY_CURRENT_USER
Case REG_OPTIONS
hKey = HKEY_CURRENT_USER
Case REG_SETTINGS
hKey = HKEY_CURRENT_USER
Case Else
hKey = HKEY_CURRENT_USER
End Select
CreateNewKey hKey, mstrVendor & App.Title & "\" & Section
RegistryError = SetKeyValue(hKey, mstrVendor & App.Title & "\" & Section, Key, vSetting, lValueType)
End Sub
Public Function RegGet(Section As String, Key As String, Optional Default As String) As Variant
Dim lRetValue As Long, hKey As Long
On Error Resume Next
RegistryError = ERROR_NONE
Select Case Section
Case ""
hKey = HKEY_CURRENT_USER
Case REG_OPTIONS
hKey = HKEY_CURRENT_USER
Case REG_SETTINGS
hKey = HKEY_CURRENT_USER
Case Else
hKey = HKEY_CURRENT_USER
End Select
'If App.ProductName = "" Then MsgBox "Error: No Product Name for this project!", vbCritical, "GetReg()": End
RegGet = QueryValue(hKey, mstrVendor & App.Title & "\" & Section, Key, lRetValue)
If lRetValue <> ERROR_NONE Then RegGet = Default
End Function
Public Sub RegDel(Optional Section As Variant)
Dim hKey As Long, lRet As Long
RegistryError = ERROR_NONE
If IsMissing(Section) Then
Section = mstrVendor & App.Title
Else
Section = mstrVendor & App.Title & "\" & Section
End If
hKey = HKEY_CURRENT_USER
DeleteSetting Section
' lRet = RegDeleteKey(hKey, Section)
End Sub
Public Function DeleteSetting(ByVal Section As String, Optional ByVal Key As String = "") As Boolean
' Section Required. String expression containing the name of the section where the key setting
' is being deleted. If only section is provided, the specified section is deleted along
' with all related key settings.
' Key Optional. String expression containing the name of the key setting being deleted.
Dim nRet As Long
Dim hKey As Long
If Len(Key) Then
' Open key
nRet = RegOpenKeyEx(HKEY_CURRENT_USER, SubKey(Section), 0&, KEY_ALL_ACCESS, hKey)
If nRet = ERROR_SUCCESS Then
' Set appropriate value for default query
If Key = "*" Then Key = vbNullString
' Delete the requested value
nRet = RegDeleteValue(hKey, Key)
Call RegCloseKey(hKey)
End If
Else
' Open parent key
nRet = RegOpenKeyEx(HKEY_CURRENT_USER, SubKey(), 0&, KEY_ALL_ACCESS, hKey)
If nRet = ERROR_SUCCESS Then
' Attempt to delete whole section
nRet = RegDeleteKey(hKey, Section)
Call RegCloseKey(hKey)
End If
End If
DeleteSetting = (nRet = ERROR_SUCCESS)
End Function
' ********************************************
' Private Methods
' ********************************************
Private Function SubKey(Optional ByVal Section As String = "") As String
' Build SubKey from known values
SubKey = mstrVendor '& App.Title
If Len(Section) Then
SubKey = SubKey & "\" & Section
End If
End Function