Results 1 to 6 of 6

Thread: Populating array with values from unknown registry keys

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2007
    Posts
    159

    Question 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...
    If my post helped you, please rate it. Thanks.

  2. #2
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    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?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2007
    Posts
    159

    Re: Populating array with values from unknown registry keys

    Quote Originally Posted by incidentals View Post
    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...
    If my post helped you, please rate it. Thanks.

  4. #4
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: Populating array with values from unknown registry keys

    show how and we can go from there

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width