OK guys, here is a toughy. How do you get the listing of all the installed applications on a computer. I need their names, icons, and locations. I can derive the icons and names if I have to...but I really dont wanna. What I am looking for is exactly like the 'Open with...' dialog box in Windows. But I want to have control over the GUI...so I need the program list in VB.
I have been searching these forums for about a week now...i've probably answered over 50 other forum questions just trying to find an answer to mine.
I'm really backed into a corner here, any help would be appreciated.
Thanks,
Joe B. Lively
Lothar Haensler
January 13th, 2000, 02:24 AM
I'd try the following approach:
- use Registry API (RegEnumKeys) to get all entries under HKEY_CLASSES_ROOT
- ignore those keys, that start with a dot
- for each subkey check to see if you can find a subkey named "shell". If so, you have found an application with that has registered one or more file types. Thus, it's a candidate for adding to your list.
Aaron Young
January 13th, 2000, 10:13 AM
I did something similar a while ago for another post, here's the code I came up with:
Add a Listbox and a Picturebox to a Form..
private Declare Function RegCloseKey Lib "advapi32.dll" (byval hKey as Long) as Long
private Declare Function RegEnumKey Lib "advapi32.dll" Alias "RegEnumKeyA" (byval hKey as Long, byval dwIndex as Long, byval lpName as string, byval cbName as Long) as Long
private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (byval hKey as Long, byval lpSubKey as string, phkResult 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 DrawIconEx Lib "user32" (byval hdc as Long, byval xLeft as Long, byval yTop as Long, byval hIcon as Long, byval cxWidth as Long, byval cyWidth as Long, byval istepIfAniCur as Long, byval hbrFlickerFreeDraw as Long, byval diFlags as Long) as Long
private Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (byval hInst as Long, byval lpszExeFileName as string, byval nIconIndex as Long) as Long
private Const HKEY_CLASSES_ROOT = &H80000000
private aIcons() as string
private Sub Form_Load()
Dim sType as string 'Ext.
Dim sName as string 'Name of File Type
Dim sFile as string 'File Used for Default Icon
Dim iIndex as Integer
Dim lRegKey as Long
List1.FontName = "Courier"
iIndex = 1
sType = Space(255)
'Enumerate all Extensions in the CLASSES Hive..
Do While RegEnumKey(HKEY_CLASSES_ROOT, iIndex, byval sType, 255) = 0
If Left(sType, 1) <> "." then Exit Do
'Store Icon Info in an Array Linked by ListIndex
ReDim Preserve aIcons(iIndex - 1)
sType = Left(sType, InStr(sType, Chr(0)) - 1)
'get this Extensions Name, eg - .zip = WinZip
If RegOpenKey(HKEY_CLASSES_ROOT, byval sType, lRegKey) = 0 then
sName = Space(255)
Call RegQueryValueEx(lRegKey, byval "", 0&, 1, byval sName, 255)
If InStr(sName, Chr(0)) then sName = Left(sName, InStr(sName, Chr(0)) - 1)
Call RegCloseKey(lRegKey)
If len(Trim(sName)) then
'Look for a Default Icon for this Type..
If RegOpenKey(HKEY_CLASSES_ROOT, sName & "\DefaultIcon\", lRegKey) = 0 then
sFile = Space(255)
Call RegQueryValueEx(lRegKey, byval "", 0&, 1, byval sFile, 255)
If InStr(sFile, Chr(0)) then sFile = Left(sFile, InStr(sFile, Chr(0)) - 1)
Call RegCloseKey(lRegKey)
aIcons(iIndex - 1) = sFile
End If
End If
End If
List1.AddItem Left(sType & Space(10), 10) & " - " & sName
sType = Space(255)
iIndex = iIndex + 1
Loop
End Sub
private Sub List1_Click()
Dim sFile as string
Dim iIndex as Integer
Dim lIcon as Long
Picture1.Cls
on error GoTo IconErr
'get the Icon from the File Stored in the Array for this File Type
sFile = Left$(aIcons(List1.ListIndex), InStr(aIcons(List1.ListIndex), ",") - 1)
iIndex = Val(mid$(aIcons(List1.ListIndex), InStr(aIcons(List1.ListIndex), ",") + 1))
lIcon = ExtractIcon(App.hInstance, sFile, iIndex)
Call DrawIconEx(Picture1.hdc, 0, 0, lIcon, 32, 32, 0, 0, 3)
IconErr:
End Sub
Aaron Young
Analyst Programmer
ajyoung@pressenter.com
aarony@redwingsoftware.com
AndyK
January 13th, 2000, 06:55 PM
And what's wrong with Aaron's code? you should at least rate his code for just replying, he didn't have to spend few mins on you just for you to ignore it.....
Lively
January 14th, 2000, 12:53 AM
Andy,
I am up against a extreme deadline. I just finihed my code about 20 minutes ago. I had planned to send both Aaron and Lorthar personal responses Friday morning when I got back to the office. I found both of their code very useful and acutally implmented a hybrid of both. I also added the ability to display the Icon in a list box. When I polish up the code this week, I plan on posting it back to this thread for other people to use. Oh, and guess who will get top billing....yep Aaron and Lorthar.
Sorry if I broke an ettequite rule, I was just under a tight deadline...which i'm sure you can appreciate.
Thank for keeping us coders straight :)
Joe B. Lively
Lively
January 14th, 2000, 12:56 AM
Aaron,
Thanks for the start Aaron....it really help out. I will post my results here sometime next week so you can see the finished product.
Also, see my response to Andy in the folling threads...sorry for not rating you sonner.
Joe B. Lively
Lively
January 14th, 2000, 01:00 AM
Lothar,
Thanks for the tip...It got pretty tough dealing with all the crazy exceptions. So I switched to looking at all the .ext files instead. Then, once I got a list of the registered extensions, I used a dummy file and the findexecutableA function. It was much easier to parce out that way.
I will post my results here next week so you can take a look at it.
thanks again,
Joe B. Lively
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.