Populating array with values from unknown registry keys
First of all, I have searched for information on enumerating registry keys and values, and I'm now drowning in information, and have gotten myself into a complete mess.
I'm hoping that if I explain what it is that I am attempting to do, someone can help me with the code:-
I want to create an array of software applications made by a specific publisher that are installed on a PC.
What I need to do, is search the HKEY_LOCAL_MACHINE\Microsoft\Software\Windows\CurrentVersion\Uninstall registry key. For each subkey, I need to test if the 'Publisher' value matches a specific string, and if it does, I want to add the 'DisplayName' and 'DisplayVersion' values from the same subkey to the array.
Thank you...
Re: Populating array with values from unknown registry keys
so can you open the hive an dget to HKEY_LOCAL_MACHINE\Microsoft\Software\Windows\CurrentVersion\Uninstall
yet, is the first question?
Re: Populating array with values from unknown registry keys
Quote:
Originally Posted by
incidentals
so can you open the hive an dget to HKEY_LOCAL_MACHINE\Microsoft\Software\Windows\CurrentVersion\Uninstall
yet, is the first question?
Yes I can...
Re: Populating array with values from unknown registry keys
show how and we can go from there
Re: Populating array with values from unknown registry keys
What registry code are you using? I don't have my samples in front of me, but there is a registry call that will get all the subkeys in one call, if I recall correctly. From there you can loop thru each one returned and see if it has a Publisher value. If so, get the DisplayName & DisplayVersion values
Re: Populating array with values from unknown registry keys
Here's a class that may be helpful:
http://www.vbaccelerator.com/codelib...g/registry.htm
And here's some code that attempts to do what you want:
Code:
Option Explicit
Private Sub Form_Load()
Dim Apps() As String, ACnt As Long
Dim Vals() As String, VCnt As Long
Dim SKey As String
Dim i As Long
Dim j As Long
Dim Publisher As String
Dim FoundPub As Boolean
Dim oReg As cRegistry
Set oReg = New cRegistry
oReg.ValueType = REG_SZ
oReg.ClassKey = HKEY_LOCAL_MACHINE
SKey = "SOFTWARE\Microsoft\Windows\Currentversion\Uninstall"
Publisher = "Microsoft Corporation" 'change as desired
oReg.SectionKey = SKey
'Read all Uninstall Section App names
oReg.EnumerateSections Apps, ACnt
If ACnt Then
For i = 1 To ACnt
oReg.SectionKey = SKey & "\" & Apps(i)
'Read the keys for each app, looking for Publisher
oReg.EnumerateValues Vals, VCnt
If VCnt Then
FoundPub = False
For j = 1 To VCnt
If Vals(j) = "Publisher" Then 'found a 'Publisher' key
oReg.ValueKey = Vals(j)
If oReg.Value = Publisher Then
FoundPub = True 'found the right one
Exit For
End If
End If
Next
'Now read the array again, since desired
'values may have been before 'Publisher'
If FoundPub Then
For j = 1 To VCnt
If Vals(j) = "DisplayName" Then
oReg.ValueKey = Vals(j)
Debug.Print "Disp Name: " & oReg.Value
Debug.Print "App: " & Apps(i)
End If
If Vals(j) = "DisplayVersion" Then
oReg.ValueKey = Vals(j)
Debug.Print "Disp Vers: " & oReg.Value
End If
If Vals(j) = "UninstallString" Then
oReg.ValueKey = Vals(j)
Debug.Print "Uninstall: " & oReg.Value
End If
'add other desired keys if desired
Next
End If
End If
Next
End If
End Sub