"Rick Rothstein" <***@NOSPAMcomcast.net> wrote in message news:***@TK2MSFTNGP11.phx.gbl
<cut>
Post by Rick RothsteinI was going to do a time test on my computer for comparison; however,
your program quit working midway through with a Runtime Error 13 -
Type Mismatch. The error occurs in the EnumKey subroutine on the
GetRegValue function call within the Debug.Print statement. I've not
done WMI stuff before, so I don't know what properties I can
reference for the WMIReg object to report to you; but the other
arguments are as follows if it helps any
HiveKey = -2147483647
SubKey = Software\VB and VBA Program Settings\vbAdvance\Toolbar
aEntries(k) = ButtonData
aTypes(k) = 3
The GetRegValue is returning a variant with the data and in the case of a
REG_BINARY value that is a byte array which the Debug.Print chokes on. I
didn't happen to have any binary values on this system so I did not think to
check for that. I separated out the call and check the return type in this
version:
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1
Private Const REG_EXPAND_SZ = 2
Private Const REG_BINARY = 3
Private Const REG_DWORD = 4
Private Const REG_MULTI_SZ = 7
Private Sub Main()
Dim oWMIReg As Object
Set oWMIReg = GetObject("winmgmts:root/default:StdRegProv")
EnumKey oWMIReg, HKEY_CURRENT_USER, "Software\VB and VBA Program Settings"
Set oWMIReg = Nothing
End Sub
Private Sub EnumKey(ByVal WMIReg As Object, ByVal HiveKey As Long, _
ByVal SubKey As String, Optional IndentLevel As Long)
Dim aEntries As Variant ' array of values/keys
Dim aTypes As Variant ' array of value types
Dim vData As Variant
Dim k As Long ' for enumerating
Debug.Print Space$(IndentLevel * 3) & SubKey
WMIReg.EnumValues HiveKey, SubKey, aEntries, aTypes
If IsArray(aEntries) Then
For k = LBound(aEntries) To UBound(aEntries)
vData = GetRegValue(WMIReg, HiveKey, SubKey, aEntries(k), aTypes(k))
If IsArray(vData) Then vData = "{array}" ' just to protect the
Debug.Print
Debug.Print Space$(IndentLevel * 3 + 3) & aEntries(k) & _
" [" & aTypes(k) & "]=" & vData
Next
End If
WMIReg.EnumKey HiveKey, SubKey, aEntries
If IsArray(aEntries) Then
For k = LBound(aEntries) To UBound(aEntries)
Debug.Print Space$(IndentLevel * 3 + 3) & aEntries(k)
EnumKey WMIReg, HiveKey, SubKey & "\" & aEntries(k), IndentLevel + 1
Next
End If
End Sub
Function GetRegValue(ByVal RegObject, ByVal HiveKey, ByVal SubKey, _
ByVal ValueName, ByVal ValueType)
Dim vValue, x
Select Case ValueType
Case REG_SZ, REG_EXPAND_SZ:
x = RegObject.GetStringValue(HiveKey, SubKey, ValueName, vValue)
Case REG_MULTI_SZ:
x = RegObject.GetMultiStringValue(HiveKey, SubKey, ValueName, vValue)
Case REG_BINARY:
x = RegObject.GetBinaryValue(HiveKey, SubKey, ValueName, vValue)
Case REG_DWORD:
x = RegObject.GetDWordValue(HiveKey, SubKey, ValueName, vValue)
End Select
If x = 0 Then GetRegValue = vValue
End Function
On my system it runs too fast to bother timing; it's a fraction of a second.
--
Reply to the group so all can participate
VB.Net... just say "No"