Sysinternals Homepage
Forum Home Forum Home > Windows Discussions > Internals
  New Posts New Posts RSS Feed - Finding all installed programs from the registry
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Finding all installed programs from the registry

 Post Reply Post Reply Page  12>
Author
Message
Chris128 View Drop Down
Groupie
Groupie
Avatar

Joined: 14 August 2009
Location: England
Status: Offline
Points: 75
Post Options Post Options   Thanks (1) Thanks(1)   Quote Chris128 Quote  Post ReplyReply Direct Link To This Post Topic: Finding all installed programs from the registry
    Posted: 04 December 2009 at 9:01pm
Hi Guys,
 
Basically I am writing a vb.net program that finds all installed programs on a PC, exactly like Add/Remove Programs does.
So I thought all I would need to do is loop through the keys in HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall and that would be it... unfortunately not, that only gets about half of the programs installed on my PC.

From using Process Monitor to watch which registry keys Add/Remove Programs accesses, I have found that I need to look at several other keys as well.... and after playing around with this for a while I have got it to work pretty much exactly like Add/Remove Programs but it still has the odd problem where it will get say 1 more program than Add/Remove Programs does. On my Windows 7 PC my code always picks up Microsoft Choice Guard as a program, where as Add/Remove Programs does not show it. On my Windows XP test machine it picks up just one random Windows Update, which obviously Add/Remove Programs does not show unless you have the Show Updates thing ticked. I have got my code to check the ReleaseType value in each key to see if it is "Hotfix", "Update Rollup", "Service Pack" etc but the window update my program is showing does not have the ReleaseType value at all anyway :(
 
So basically, I'm just wondering if there is anyone out there with a good understanding of how add/remove programs does its thing that might be able to help me out a bit?
 
 
If you want to see my VB.NET code then let me know but here is the basic logic of my program:
 
1. Loop through all subkeys in HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall
 
2. For each subkey, do the following:
--Check to see if the SystemComponent value exists and is set to 1 - if it is then move on to the next subkey
--Check to see if the WindowsInstaller value exists and is set to 1 - if it is then move on to next subkey
--Check to see if the UninstallString value exists - if it does not then move on to next subkey
--Check the ReleaseType value, if it is hotix or service pack etc then move on to next subkey
--Check the ParentKeyName value, if it exists then move on to next subkey
--Check to see if the DisplayName value exists - if it does then add this name to our list of installed programs
 
3. Repeat this same process for all subkeys in HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall if it exists.
 
4. Loop through all users in HKEY_USERS and for each one, loop through the subkeys in HKU\USER-SID-HERE\Software\Microsoft\Windows\CurrentVersion\Uninstall and do the exact same thing described in step 2
 
5. Whilst looping through all users in HKEY_USERS, also check HKU\USER-SID-HERE\Software\Microsoft\Installer\Products and for each subkey in there do the following:
--Check to see if a subkey with the same GUID name exists in HKLM\Software\Microsoft\Windows\CurrentVersion\Installer\UserData\USER-SID-HERE\Products - if it does then check to see if the SystemComponent value in the InstallProperties subkey is set to 1 - if it is then move on to the next subkey
--Read the ProductName value and add it to our list of installed programs
 
6. Loop through all subkeys in HKLM\Software\Classes\Installer\Products and for each one do the following:
--Check to see if a subkey with the same GUID name exists in HKLM\Software\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products - if it doesnt then move on to the next subkey
--Check the SystemComponent value is not set to 1 - if it is set to 1 then move on to next subkey
--Check the WindowsInstaller value exists and is set to 1 - if it is not then move to next subkey
--Read the ProductName value and add it to our list of installed programs
 
THE END Big smile
 
Anyone see anything I am missing or doing wrong? Like I said, this works fairly well but just seems to show one or two programs that Add/Remove Programs does not for some reason...
One thing I am also particularly struggling with is how Windows determines whether an installed program is an update or not. If it has the ReleaseType value or ParentKeyName set then its easy to tell but if not then I dont understand how it knows its not just another normal program..
 
Thanks!
Chris


 
 
     
Back to Top
Chris128 View Drop Down
Groupie
Groupie
Avatar

Joined: 14 August 2009
Location: England
Status: Offline
Points: 75
Post Options Post Options   Thanks (0) Thanks(0)   Quote Chris128 Quote  Post ReplyReply Direct Link To This Post Posted: 04 December 2009 at 10:14pm
Originally posted by Chris128 Chris128 wrote:

One thing I am also particularly struggling with is how Windows determines whether an installed program is an update or not. If it has the ReleaseType value or ParentKeyName set then its easy to tell but if not then I dont understand how it knows its not just another normal program..
    
Well through a bit of testing I just discovered how Add/Remove Programs decides whether an item under the Uninstall key is an update or a normal program if it doesnt have the ReleaseType or ParentKeyName value - it looks to see if the name of the subkey starts with KB and has 6 numbers after it! With all these GUIDs and other IDs being referenced all over the place I didnt think for a minute that they would be basing whether or not they show an item on something as simple as that! Also very unfortunate for anyone that creates a program that has an installer name of KB + 6 numbers LOL
 
I could still do with some help on why Microsoft Choice Guard shows up in my program but not in Add/Remove though :)


Edited by Chris128 - 04 December 2009 at 10:15pm
Back to Top
Chris128 View Drop Down
Groupie
Groupie
Avatar

Joined: 14 August 2009
Location: England
Status: Offline
Points: 75
Post Options Post Options   Thanks (0) Thanks(0)   Quote Chris128 Quote  Post ReplyReply Direct Link To This Post Posted: 05 December 2009 at 3:59am

OK I've narrowed it down a little more...

In the following key HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{XXXXX-XXXXXX-XXXXX} (Where XXXX-XXXX is the GUID name of the installer package) I found the one for Choice Guard and noticed that inside it there was the SystemComponent flag set, so I deleted that value and it then showed up in Add/Remove Programs. So my code obviously needs to check to see if this flag exists... the problem is that it already does this! However, what my code does is just ignores that entry in the Uninstall subkey if the SystemComponent flag is set - what Windows seems to do is ignore that entry in the Uninstall subkey and any entries for that same product in HKLM\Software\Classes\Installer\Products . What I cant understand though is how it links these 2 things together, because the GUID name used in the first key I mentioned is not the same as the Hex/Guid/whatever name that the same product has in the second location. The only thing that is the same is the display name and I'm sure it cant go on that because there are some other products in both locations that have the same name in both and have SystemComponent set in one, yet the product still appears in Add/Remove Programs.

I also just noticed that if I delete the SystemComponent flag for one of the other programs that already appears in Add/Remove Programs it then appears in there twice... even though for another program that appears in Add/Remove Programs it already does not have the SystemComponent flag anywayAngry this is getting very confusing

Back to Top
Bruce9 View Drop Down
Groupie
Groupie


Joined: 30 May 2008
Status: Offline
Points: 47
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bruce9 Quote  Post ReplyReply Direct Link To This Post Posted: 07 December 2009 at 2:08pm
See  "Add/Remove Programs " source code.
(posted on Win32 group http://tinyurl.com/yjy3ajr , uses COM, C++ code)
Back to Top
Chris128 View Drop Down
Groupie
Groupie
Avatar

Joined: 14 August 2009
Location: England
Status: Offline
Points: 75
Post Options Post Options   Thanks (0) Thanks(0)   Quote Chris128 Quote  Post ReplyReply Direct Link To This Post Posted: 07 December 2009 at 2:25pm
Sorry but that link you posted doesnt seem to contain any relevant information. I searched for Add/Remove Programs,Add Remove Programs,Add Remove Programs Source Code and various other things and it didnt find anything useful
Back to Top
nullptr View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 April 2008
Location: Australia
Status: Offline
Points: 763
Post Options Post Options   Thanks (0) Thanks(0)   Quote nullptr Quote  Post ReplyReply Direct Link To This Post Posted: 07 December 2009 at 2:55pm
Try searching: list installed programs 
Back to Top
Chris128 View Drop Down
Groupie
Groupie
Avatar

Joined: 14 August 2009
Location: England
Status: Offline
Points: 75
Post Options Post Options   Thanks (0) Thanks(0)   Quote Chris128 Quote  Post ReplyReply Direct Link To This Post Posted: 17 December 2009 at 9:03pm
Thanks I found the references to IShellAppManager and IEnumInstalledApps but it seems that there is very little on the internet about these two items (cant remember the last time I did a google search and only got one page of results!) so I dont even know where those APIs are defined, so I cant begin to try and call them from my .NET application :(
Back to Top
Chris128 View Drop Down
Groupie
Groupie
Avatar

Joined: 14 August 2009
Location: England
Status: Offline
Points: 75
Post Options Post Options   Thanks (0) Thanks(0)   Quote Chris128 Quote  Post ReplyReply Direct Link To This Post Posted: 15 January 2010 at 7:50pm

Just for anyone interested, I have pretty much finished this program now and it works quite well - on every PC I have tested the latest version on it has detected exactly the same programs that Add/Remove Programs detected (apart from Windows Updates or anything that is only displayed when you tick the Include Updates box in Add/Remove programs, as I am not bothered about detecting them really).

I didnt end up using the Windows APIs mentioned and just did it all myself by looking up various registry keys. I figured out how to convert the GUID name shown in the Uninstall key to a windows installer ID - if you split the original GUID string up into 2 halfs after the second hyphen, in the first half each block is just reversed and in the second section characters are reversed in groups of 2. Here's an example:�

Original String:
{01C5A10F-AD9B-405B-853A-6659841A1242}
Converted String
F01A5C10B9DAB50458A3669548A12124

Its probably easier to see what I mean if I display the strings like this:

Original String:
01C5A10F AD9B 405B 85 3A 66 59 84 1A 12 42
Converted String
F01A5C10 B9DA B504 58 A3 66 95 48 A1 21 24

Anyway, once I had figured that out, I just basically made my app loop through the Uninstall key and for each item, if the WindowsInstaller flag is set, then it converts the GUID name of the current key (as explained above) and then looks in Classes\Installer\Products for that converted string as the name of one of the subkeys. If it finds it then it pulls information from that subkey.

Obviously there is a bit more to it than that but if anyone wants to see exactly how my code works the full source code (and an example application that uses it) is here: http://cjwdev.wordpress.com/2010/01/06/enumerate-installed-programs/

Cheers, Chris



Edited by Chris128 - 12 April 2010 at 2:30pm
Back to Top
hwee View Drop Down
Newbie
Newbie


Joined: 08 February 2011
Location: US
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote hwee Quote  Post ReplyReply Direct Link To This Post Posted: 08 February 2011 at 7:20pm

Hi Christ,

I tried your program and it worked great.  However, i was wondering that we can display the GUID (key) of each installed software.  By the way, I was trying to findout the GUID of the the McAfee that is install on the PC.  If you have a minute, could you give me some suggestions?  Thanks

HHH
Back to Top
Drewfus View Drop Down
Groupie
Groupie


Joined: 12 February 2010
Status: Offline
Points: 44
Post Options Post Options   Thanks (0) Thanks(0)   Quote Drewfus Quote  Post ReplyReply Direct Link To This Post Posted: 08 February 2011 at 10:55pm
I requested a similar program on the Utilities Suggestions page.
 
 
Back to Top
 Post Reply Post Reply Page  12>
  Share Topic   

Forum Jump Forum Permissions View Drop Down