Results 1 to 7 of 7

Thread: This is some code to list all installed apps

  1. #1
    Tygur
    Guest

    This is some code to list all installed apps

    I just made some code for someone that lists all installed apps. I just decided to throw it in here for anyone who might be interested in using it.

    It's a function, called GetInstalledApps, which returns an array with the names of all the installed apps. It should be easy enough to figure out how to use.

    The code is based on information gathered from the MSDN Library. It has lots of information for people who want to make their own installers.

    Here's the code:
    VB Code:
    1. 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
    2. 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
    3. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    4. 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
    5. Private Const HKEY_LOCAL_MACHINE = &H80000002
    6. Private Const KEY_QUERY_VALUE = &H1
    7. Private Const KEY_ENUMERATE_SUB_KEYS = &H8
    8. Private Const ERROR_NO_MORE_ITEMS = 259&
    9. Private Const REG_SZ = 1
    10. Private Type FILETIME
    11.         dwLowDateTime As Long
    12.         dwHighDateTime As Long
    13. End Type
    14.  
    15. Function GetInstalledApps() As String()
    16. Dim RetArray() As String
    17. Dim hParentKey As Long
    18. Dim hSubKey As Long
    19. Dim lIndex As Long
    20. Dim sAppID As String
    21. Dim lAppID As Long
    22. Dim sAppName As String
    23. Dim lAppName As Long
    24. Dim ValueType As Long
    25. Dim DummyTime As FILETIME
    26. Dim UbRetArray As Long
    27. Dim QVErr As Long
    28. Dim sErr As String
    29. Dim lErr As Long
    30.  
    31. UbRetArray = -1
    32. If RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Uninstall", 0, KEY_ENUMERATE_SUB_KEYS, hParentKey) = 0 Then
    33.     sAppID = Space(64)
    34.     lAppID = 64
    35.     Do While RegEnumKeyEx(hParentKey, lIndex, sAppID, lAppID, 0, vbNullString, 0, DummyTime) = 0
    36.         sAppID = Left(sAppID, lAppID)
    37.         If RegOpenKeyEx(hParentKey, sAppID, 0, KEY_QUERY_VALUE, hSubKey) = 0 Then
    38.             lAppName = 0
    39.             If RegQueryValueEx(hSubKey, "DisplayName", 0, ValueType, ByVal 0, lAppName) = 0 Then
    40.                 If ValueType = REG_SZ Then
    41.                     sAppName = Space(lAppName)
    42.                     RegQueryValueEx hSubKey, "DisplayName", 0, 0, ByVal sAppName, lAppName
    43.                     sAppName = Left(sAppName, lAppName - 1)
    44.                     UbRetArray = UbRetArray + 1
    45.                     ReDim Preserve RetArray(UbRetArray)
    46.                     RetArray(UbRetArray) = sAppName
    47.                 End If
    48.             End If
    49.             RegCloseKey hSubKey
    50.             hSubKey = 0
    51.         End If
    52.         lIndex = lIndex + 1
    53.         sAppID = Space(64)
    54.         lAppID = 64
    55.     Loop
    56.     RegCloseKey hParentKey
    57. End If
    58. GetInstalledApps = RetArray
    59. End Function

    Have fun

  2. #2
    Tygur
    Guest
    I was just looking through the code and I realized that the declaration of a variable called QVErr is still in that function. It's a variable I was using to test it out, and its declaration can be safely removed.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Thumbs up

    This is VERY cool Tygur!!!!!!!!!!!!

    Also, for those interested, here is what I did.

    Move the declaration for RetArray() out of the GetInstalledApps function, and make it a Private, form level variable
    (also, as Tygur suggested, you can completley delete the declaration for QVErr).

    Place a listbox on your form, and this code in a button click event (or Form_Load, or where ever you want it).
    VB Code:
    1. Private Sub Command1_Click()
    2. GetInstalledApps
    3. Dim i As Long
    4. For i = LBound(RetArray) To UBound(RetArray)
    5.     List1.AddItem RetArray(i)
    6. Next
    7. End Sub

    Again, fine job Tygur. This routine will make a fine addition to my code library!

  4. #4
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    I need to get in the habit of using a code database. I currently have a huge folder with unorganized vb code . I need something that goes through the folder and makes a database, so I can just add more files to the folder and the database will be updated. Did I give anyone an idea for a project?
    retired member. Thanks for everything

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Yes, you gave yourself an idea for a project!!!!

    You want a database application that stores stuff, build one.

  6. #6
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197
    im already busy with something else
    retired member. Thanks for everything

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: This is some code to list all installed apps

    In doing a search I ran across this thread from 2002 which I feel should be in the CodeBank, so I moved it here.

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