1 | Namespace ActiveBasic
|
---|
2 | Namespace Windows
|
---|
3 |
|
---|
4 | Enum RegistryValueKind
|
---|
5 | Binary = REG_BINARY
|
---|
6 | DWord = REG_DWORD
|
---|
7 | ExpandString = REG_EXPAND_SZ
|
---|
8 | MultiString = REG_MULTI_SZ
|
---|
9 | QWord = REG_QWORD
|
---|
10 | String = REG_SZ
|
---|
11 | Unknown = 0
|
---|
12 | End Enum
|
---|
13 |
|
---|
14 | Enum RegistryValueOptions
|
---|
15 | DoNotExpandEnvironmentNames
|
---|
16 | None
|
---|
17 | End Enum
|
---|
18 |
|
---|
19 | Enum RegistryHive
|
---|
20 | ClassesRoot = HKEY_CLASSES_ROOT
|
---|
21 | CurrentConfig = HKEY_CURRENT_CONFIG
|
---|
22 | CurrentUser = HKEY_CURRENT_USER
|
---|
23 | DynData = HKEY_DYN_DATA
|
---|
24 | LocalMachine = HKEY_LOCAL_MACHINE
|
---|
25 | PerformanceData = HKEY_PERFORMANCE_DATA
|
---|
26 | Users = HKEY_USERS
|
---|
27 | End Enum
|
---|
28 |
|
---|
29 | Class RegistryKey
|
---|
30 | Implements System.IDisposable
|
---|
31 |
|
---|
32 | Protected
|
---|
33 | handle As HKEY
|
---|
34 | rootkey As HKEY
|
---|
35 | rootkeyname As String
|
---|
36 | subkeyname As String
|
---|
37 |
|
---|
38 | Virtual Sub ~RegistryKey( )
|
---|
39 | This.Dispose( )
|
---|
40 | End Sub
|
---|
41 |
|
---|
42 | Public
|
---|
43 | 'キーの名前を取得します。
|
---|
44 | Function Name( ) As String
|
---|
45 | Dim name = rootkeyname + "\" + subkeyname
|
---|
46 | Return name
|
---|
47 | End Function
|
---|
48 |
|
---|
49 | '現在のキーのサブキーの数を取得します。
|
---|
50 | Function SubKeyCount( ) As Long
|
---|
51 | Dim count As DWord
|
---|
52 | RegQueryInfoKey( This.handle, NULL, 0, NULL, VarPtr(count), NULL, NULL, NULL, NULL, NULL, NULL, NULL )
|
---|
53 | Return count
|
---|
54 | End Function
|
---|
55 |
|
---|
56 | 'キーの値の数を取得します。
|
---|
57 | Function ValueCount( ) As Long
|
---|
58 | Dim count As DWord
|
---|
59 | RegQueryInfoKey( This.handle, NULL, 0, NULL, NULL, NULL, NULL, VarPtr(count), NULL, NULL, NULL, NULL )
|
---|
60 | Return count
|
---|
61 | End Function
|
---|
62 |
|
---|
63 | Public
|
---|
64 | 'キーを閉じ、キーの内容が変更されている場合はディスクへフラッシュします。
|
---|
65 | Sub Close( )
|
---|
66 | This.Flush()
|
---|
67 | RegCloseKey( This.handle )
|
---|
68 | End Sub
|
---|
69 |
|
---|
70 | '新しいサブキーを作成するか、または既存のサブキーを開きます。
|
---|
71 | Function CreateSubKey( subkey As String ) As RegistryKey
|
---|
72 | Dim key As Detail._System_RegistryKey
|
---|
73 | key.Root( This.rootkey )
|
---|
74 | key.SubKey( subkey )
|
---|
75 | key.Create( )
|
---|
76 | Return key
|
---|
77 | End Function
|
---|
78 |
|
---|
79 | ' Function CreateSubKey( subkey As String, permissionCheck As RegistryKeyPermissionCheck ) As RegistryKey
|
---|
80 | ' TODO
|
---|
81 | ' End Function
|
---|
82 |
|
---|
83 | ' Function CreateSubKey( subkey As String, permissionCheck As RegistryKeyPermissionCheck, registrySecurity As RegistrySecurity ) As RegistryKey
|
---|
84 | ' TODO
|
---|
85 | ' End Function
|
---|
86 |
|
---|
87 | '指定したサブキーを削除します。文字列 subkey では、大文字と小文字は区別されません。
|
---|
88 | Sub DeleteSubKey ( subkey As String )
|
---|
89 | End Sub
|
---|
90 | Sub DeleteSubKey ( subkey As String, throwOnMissingSubKey As Boolean )
|
---|
91 | End Sub
|
---|
92 |
|
---|
93 | 'サブキーとその子サブキーを再帰的に削除します。文字列 subkey では、大文字と小文字は区別されません。
|
---|
94 | Sub DeleteSubKeyTree ( subkey As String )
|
---|
95 | End Sub
|
---|
96 |
|
---|
97 | '指定した値をこのキーから削除します。
|
---|
98 | Sub DeleteValue ( name As String )
|
---|
99 | RegDeleteValue( This.handle, name )
|
---|
100 | End Sub
|
---|
101 | Sub DeleteValue ( name As String, throwOnMissingValue As Boolean )
|
---|
102 | End Sub
|
---|
103 |
|
---|
104 | '指定したオープン レジストリ キーのすべての属性をこのレジストリへ書き込みます。
|
---|
105 | Sub Flush()
|
---|
106 | RegFlushKey( This.handle )
|
---|
107 | End Sub
|
---|
108 |
|
---|
109 | 'すべてのサブキーの名前が格納されている文字列の配列を取得します。
|
---|
110 | Function GetSubKeyNames() As System.Collections.Generic.List<String>
|
---|
111 | Dim list As System.Collections.Generic.List<String>
|
---|
112 |
|
---|
113 | Dim subkey[255] As TCHAR
|
---|
114 | Dim dwsubkey=255 As DWord
|
---|
115 |
|
---|
116 | Dim index=0 As DWord
|
---|
117 | While ERROR_NO_MORE_ITEMS <> RegEnumKeyEx( This.handle, index, subkey, dwsubkey, NULL, NULL, 0, NULL )
|
---|
118 | list.Add( New String(subkey) )
|
---|
119 | dwsubkey = 255
|
---|
120 | index++
|
---|
121 | Wend
|
---|
122 | Return list
|
---|
123 | End Function
|
---|
124 |
|
---|
125 | '指定した名前に関連付けられている値を取得します。
|
---|
126 | Function GetValue ( name As String ) As Object
|
---|
127 | Dim dwType As DWord
|
---|
128 | If ERROR_SUCCESS <> RegQueryValueEx( This.handle, ToTCStr(name), 0, VarPtr(dwType), NULL, NULL ) Then
|
---|
129 | Return Nothing
|
---|
130 | End If
|
---|
131 |
|
---|
132 | Dim dwSize As DWord
|
---|
133 | Dim dwMemSize=255 As DWord
|
---|
134 | Dim pbData As *Byte
|
---|
135 | pbData = GC_malloc( dwMemSize )
|
---|
136 | Do
|
---|
137 | dwSize = dwMemSize
|
---|
138 | realloc(pbData, dwMemSize)
|
---|
139 | If ERROR_MORE_DATA = RegQueryValueEx( This.handle, ToTCStr(name), 0, VarPtr(dwType), pbData, VarPtr(dwSize) ) Then
|
---|
140 | dwMemSize += 5
|
---|
141 | Else
|
---|
142 | Exit Do
|
---|
143 | End If
|
---|
144 | Loop
|
---|
145 |
|
---|
146 | Select Case dwType
|
---|
147 | Case REG_BINARY
|
---|
148 | Return New System.Collections.Generic.List<Byte>( pbData, dwSize )
|
---|
149 | Case REG_DWORD
|
---|
150 | Dim dw As DWord
|
---|
151 | memcpy( VarPtr(dw), pbData, SizeOf(DWord) )
|
---|
152 | Return New System.UInt32( dw )
|
---|
153 | Case REG_EXPAND_SZ
|
---|
154 | Return New System.String( pbData As LPCTSTR )
|
---|
155 | Case REG_MULTI_SZ
|
---|
156 | Return New System.String( pbData As LPCTSTR )
|
---|
157 | Case REG_QWORD
|
---|
158 | Dim qw As QWord
|
---|
159 | memcpy( VarPtr(qw), pbData, SizeOf(QWord) )
|
---|
160 | Return New System.UInt64( qw )
|
---|
161 | Case REG_SZ
|
---|
162 | Return New System.String( pbData As LPCTSTR )
|
---|
163 | Case Else
|
---|
164 | Return Nothing
|
---|
165 | End Select
|
---|
166 | End Function
|
---|
167 | Function GetValue ( name As String, defaultValue As Object ) As Object
|
---|
168 | End Function
|
---|
169 | Function GetValue ( name As String, defaultValue As Object, options As RegistryValueOptions ) As Object
|
---|
170 | End Function
|
---|
171 |
|
---|
172 | '指定した名前に関連付けられた値のレジストリ データ型を取得します。
|
---|
173 | Function GetValueKind ( name As String ) As RegistryValueKind
|
---|
174 | Dim dwType As DWord
|
---|
175 | If ERROR_SUCCESS <> RegQueryValueEx( This.handle, ToTCStr(name), 0, VarPtr(dwType), NULL, NULL ) Then
|
---|
176 | Return Nothing
|
---|
177 | End If
|
---|
178 | Select Case dwType
|
---|
179 | Case REG_BINARY
|
---|
180 | Return RegistryValueKind.Binary
|
---|
181 | Case REG_DWORD
|
---|
182 | Return RegistryValueKind.DWord
|
---|
183 | Case REG_EXPAND_SZ
|
---|
184 | Return RegistryValueKind.ExpandString
|
---|
185 | Case REG_MULTI_SZ
|
---|
186 | Return RegistryValueKind.MultiString
|
---|
187 | Case REG_QWORD
|
---|
188 | Return RegistryValueKind.QWord
|
---|
189 | Case REG_SZ
|
---|
190 | Return RegistryValueKind.String
|
---|
191 | Case Else
|
---|
192 | Return RegistryValueKind.Unknown
|
---|
193 | End Select
|
---|
194 | End Function
|
---|
195 |
|
---|
196 | 'このキーに関連付けられているすべての値の名前が格納されている文字列の配列を取得します。
|
---|
197 | Function GetValueNames() As System.Collections.Generic.List<String>
|
---|
198 | Dim list As System.Collections.Generic.List<String>
|
---|
199 |
|
---|
200 | Dim ValueName[255] As TCHAR
|
---|
201 | Dim dwValueName=255 As DWord
|
---|
202 |
|
---|
203 | Dim index=0 As DWord
|
---|
204 | While ERROR_NO_MORE_ITEMS <> RegEnumValue( This.handle, index, ValueName, dwValueName, 0, NULL, NULL, NULL )
|
---|
205 | list.Add( New String(ValueName) )
|
---|
206 | dwValueName = 255
|
---|
207 | index++
|
---|
208 | Wend
|
---|
209 | Return list
|
---|
210 | End Function
|
---|
211 |
|
---|
212 | '指定したサブキーを取得します。
|
---|
213 | Function OpenSubKey ( name As String ) As RegistryKey
|
---|
214 | Dim key As Detail._System_RegistryKey
|
---|
215 | key.Root( This.rootkey )
|
---|
216 | key.SubKey( name )
|
---|
217 | key.Open( )
|
---|
218 | Return key
|
---|
219 | End Function
|
---|
220 |
|
---|
221 | Function OpenSubKey ( name As String, writable As Boolean ) As RegistryKey
|
---|
222 | End Function
|
---|
223 |
|
---|
224 | ' Function OpenSubKey ( name As String, permissionCheck As RegistryKeyPermissionCheck ) As RegistryKey
|
---|
225 | ' TODO
|
---|
226 | ' End Function
|
---|
227 |
|
---|
228 | ' Function OpenSubKey ( name As String, permissionCheck As RegistryKeyPermissionCheck, rights As RegistryRights ) As RegistryKey
|
---|
229 | ' TODO
|
---|
230 | ' End Function
|
---|
231 |
|
---|
232 | 'レジストリ キーに名前/値ペアの値を設定します。オーバーロードに応じて、格納するデータの型または指定した RegistryValueKind に基づいてレジストリ データ型が判別されます。
|
---|
233 | Sub SetValue ( name As String, value As Object )
|
---|
234 | End Sub
|
---|
235 | Sub SetValue ( name As String, value As Object, valueKind As RegistryValueKind )
|
---|
236 | End Sub
|
---|
237 |
|
---|
238 | 'このキーの文字列形式を取得します。
|
---|
239 | Override Function ToString( ) As String
|
---|
240 | End Function
|
---|
241 |
|
---|
242 | Public
|
---|
243 | Override Sub Dispose()
|
---|
244 | This.Close( )
|
---|
245 | End Sub
|
---|
246 | End Class
|
---|
247 |
|
---|
248 | Namespace Detail
|
---|
249 |
|
---|
250 | Class _System_RegistryKey
|
---|
251 | Inherits RegistryKey
|
---|
252 |
|
---|
253 | Public
|
---|
254 | Sub Root( hkey As HKEY )
|
---|
255 | This.rootkey = hkey
|
---|
256 | Select Case This.rootkey
|
---|
257 | Case HKEY_CLASSES_ROOT
|
---|
258 | This.rootkeyname = "HKEY_CLASSES_ROOT"
|
---|
259 | Case HKEY_CURRENT_CONFIG
|
---|
260 | This.rootkeyname = "HKEY_CURRENT_CONFIG"
|
---|
261 | Case HKEY_CURRENT_USER
|
---|
262 | This.rootkeyname = "HKEY_CURRENT_USER"
|
---|
263 | Case HKEY_DYN_DATA
|
---|
264 | This.rootkeyname = "HKEY_DYN_DATA"
|
---|
265 | Case HKEY_LOCAL_MACHINE
|
---|
266 | This.rootkeyname = "HKEY_LOCAL_MACHINE"
|
---|
267 | Case HKEY_PERFORMANCE_DATA
|
---|
268 | This.rootkeyname = "HKEY_PERFORMANCE_DATA"
|
---|
269 | Case HKEY_USERS
|
---|
270 | This.rootkeyname = "HKEY_USERS"
|
---|
271 | End Select
|
---|
272 | End Sub
|
---|
273 |
|
---|
274 | Sub SubKey( subkey As String )
|
---|
275 | This.subkeyname = subkey
|
---|
276 | If This.subkeyname.EndsWith( "\" ) Then
|
---|
277 | This.subkeyname.Remove( This.subkeyname.Length - 1 )
|
---|
278 | End If
|
---|
279 | End Sub
|
---|
280 |
|
---|
281 | Sub Create()
|
---|
282 | RegCreateKeyEx( This.rootkey, ToTCStr(This.subkeyname), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_READ or KEY_WRITE, NULL, This.handle, NULL )
|
---|
283 | End Sub
|
---|
284 | ' Function Create( permissionCheck As RegistryKeyPermissionCheck ) As RegistryKey
|
---|
285 | ' TODO
|
---|
286 | ' End Function
|
---|
287 | ' Function Create( permissionCheck As RegistryKeyPermissionCheck, registrySecurity As RegistrySecurity ) As RegistryKey
|
---|
288 | ' TODO
|
---|
289 | ' End Function
|
---|
290 |
|
---|
291 | Sub Open()
|
---|
292 | RegOpenKeyEx( This.rootkey, ToTCStr(This.subkeyname), 0, KEY_READ or KEY_WRITE, This.handle )
|
---|
293 | End Sub
|
---|
294 | ' Function Open( permissionCheck As RegistryKeyPermissionCheck ) As RegistryKey
|
---|
295 | ' TODO
|
---|
296 | ' End Function
|
---|
297 | ' Function Open( permissionCheck As RegistryKeyPermissionCheck, rights As RegistryRights ) As RegistryKey
|
---|
298 | ' TODO
|
---|
299 | ' End Function
|
---|
300 |
|
---|
301 | End Class
|
---|
302 |
|
---|
303 | End Namespace
|
---|
304 |
|
---|
305 |
|
---|
306 | Class Registry
|
---|
307 | Public
|
---|
308 | Static Function ClassesRoot() As RegistryKey
|
---|
309 | Dim key As Detail._System_RegistryKey
|
---|
310 | key.Root( HKEY_CLASSES_ROOT )
|
---|
311 | Return key
|
---|
312 | End Function
|
---|
313 |
|
---|
314 | Static Function CurrentConfig() As RegistryKey
|
---|
315 | Dim key As Detail._System_RegistryKey
|
---|
316 | key.Root( HKEY_CURRENT_CONFIG )
|
---|
317 | Return key
|
---|
318 | End Function
|
---|
319 |
|
---|
320 | Static Function CurrentUser() As RegistryKey
|
---|
321 | Dim key As Detail._System_RegistryKey
|
---|
322 | key.Root( HKEY_CURRENT_USER )
|
---|
323 | Return key
|
---|
324 | End Function
|
---|
325 |
|
---|
326 | Static Function DynData() As RegistryKey
|
---|
327 | Dim key As Detail._System_RegistryKey
|
---|
328 | key.Root( HKEY_DYN_DATA )
|
---|
329 | Return key
|
---|
330 | End Function
|
---|
331 |
|
---|
332 | Static Function LocalMachine() As RegistryKey
|
---|
333 | Dim key As Detail._System_RegistryKey
|
---|
334 | key.Root( HKEY_LOCAL_MACHINE )
|
---|
335 | Return key
|
---|
336 | End Function
|
---|
337 |
|
---|
338 | Static Function PerformanceData() As RegistryKey
|
---|
339 | Dim key As Detail._System_RegistryKey
|
---|
340 | key.Root( HKEY_PERFORMANCE_DATA )
|
---|
341 | Return key
|
---|
342 | End Function
|
---|
343 |
|
---|
344 | Static Function Users() As RegistryKey
|
---|
345 | Dim key As Detail._System_RegistryKey
|
---|
346 | key.Root( HKEY_USERS )
|
---|
347 | Return key
|
---|
348 | End Function
|
---|
349 | End Class
|
---|
350 |
|
---|
351 | End Namespace
|
---|
352 | End Namespace
|
---|