Использую API, не могу понять как вывести из каталога все параметры и их значения. Не хочу использовать RegTool5.dll.
Я понял, что это делать надо через массив, т.е в RegEnumValue параметр lpData будет массивом. Пытался сделать там с For...Next - не получилось, как это реализовать?
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" _
Alias "RegOpenKeyExA" (ByVal Hkey As Long, _
ByVal lpSubKey As String, _
ByVal ulOptions As Long, _
ByVal samDesired As Long, _
phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal Hkey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" _
Alias "RegQueryValueExA" (ByVal Hkey As Long, _
ByVal lpValueName As String, _
ByVal lpReserved As Long, _
lpType As Long, _
lpData As Any, _
lpcbData As Long) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" _
Alias "RegEnumValueA" (ByVal Hkey As Long, _
ByVal dwIndex As Long, _
ByVal lpValueName As String, _
lpcbValueName As Long, _
ByVal lpReserved As Long, _
lpType As Long, _
lpData As Byte, _
lpcbData As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" _
Alias "RegEnumKeyExA" (ByVal Hkey As Long, _
ByVal dwIndex As Long, _
ByVal lpName As String, _
lpcbName As Long, _
ByVal lpReserved As Long, _
ByVal lpClass As String, _
lpcbClass As Long, _
lpftLastWriteTime As FILETIME) As Long
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_CURRENT_USER = &H80000001
Private Const READ_CONTROL = &H20000
Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const SYNCHRONIZE = &H100000
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or _
KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) _
And (Not SYNCHRONIZE))
Private Const ERROR_SUCCESS = 0&
Private Const REG_BINARY = 3
Private Const REG_DWORD = 4
Private Const REG_DWORD_BIG_ENDIAN = 5
Private Const REG_DWORD_LITTLE_ENDIAN = 4
Private Const REG_EXPAND_SZ = 2
Private Const REG_LINK = 6
Private Const REG_MULTI_SZ = 7
Private Const REG_FULL_RESOURCE_DESCRIPTOR = 9
Private Const REG_NONE = 0
Private Const ERROR_NO_MORE_ITEMS = 259&
Private Const REG_SZ = 1
Private Const KEY_ALL_ACCESS = &H2003F
Private Const dhcSuccess = 0
Public Function GetPorts(hKeyRoot As Long, strSubKey As String)
Dim hSubKey As Long
Dim cEnum As Long
Dim IngResult As Long
Dim strNameBuff As String
Dim cbNameBuff As Long
Dim IngType As Long
Dim abytData(1 To 2048) As Byte
Dim cbData As Long, msg As String
IngResult = RegOpenKeyEx(hKeyRoot, strSubKey, 0&, KEY_ALL_ACCESS, hSubKey)
If IngResult = dhcSuccess Then
msg = "Something" & vbCrLf & "---------------------------------------" & vbCrLf
Do
strNameBuff = Space$(255)
cbNameBuff = Len(strNameBuff)
Erase abytData
cbData = UBound(abytData)
IngResult = RegEnumValue(hSubKey, cEnum, strNameBuff, cbNameBuff, ByVal 0&, IngType, abytData(1), cbData)
If IngResult = dhcSuccess Then
msg = msg & IngType & vbTab & Left(strNameBuff, cbNameBuff) & vbCrLf
End If
cEnum = cEnum + 1
Loop Until IngResult <> 0
IngResult = RegCloseKey(hSubKey)
End If
MsgBox msg, , "Something"
End Function
Ответить
|