|
-
May 6th, 2011, 02:13 PM
#1
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
 Originally Posted by Blagojce
In registry under HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall I have keys which starts with "{some number" but application skip this keys and start with application name keys.
I search through the code,but didn't notice how you did this.
Those programs are programs that have been installed by a Windows Installer (MSI) setup program. For each of the registry keys under that location you mentioned, my code checks to see if they have the WindowsInstaller value within them set to 1, if they do then we just get the name of the key (so{DJFHDFH34} for example) and pass it to our GetInstallerKeyNameFromGuid function which takes the name and works out the MSI installer ID for it (which is done by just moving some of the characters around, just look at the function to see exactly what it does). Then we look for that MSI installer ID in another part of the registry (HKEY_CLASSES_ROOT\MSI_installer_ID_here) to actually get the program name and other information.
This is the part of the code that does it (within the GetUninstallKeyPrograms method):
vb.net Code:
If Not CInt(CurrentSubKey.GetValue("WindowsInstaller", 0)) = 1 Then
'...
'... irrelevent code here
'...
Else 'If WindowsInstaller
Dim ProgVersion As String = String.Empty
Dim Name As String = String.Empty
Dim FoundName As Boolean = False
Try
Dim MsiKeyName As String = GetInstallerKeyNameFromGuid(SubKeyName)
Dim CrGuidKey As RegistryKey = ClassesKey.OpenSubKey(MsiKeyName)
If Not CrGuidKey Is Nothing Then
Name = CStr(CrGuidKey.GetValue("ProductName", String.Empty))
End If
Catch ex As Exception
Debug.WriteLine(SubKeyName & " - " & ex.Message)
End Try
Hope that explains it - I know its not very straight forward, that's why it took me ages to figure it out and get this code working
-
May 7th, 2011, 01:26 PM
#2
Addicted Member
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
 Originally Posted by chris128
Those programs are programs that have been installed by a Windows Installer (MSI) setup program. For each of the registry keys under that location you mentioned, my code checks to see if they have the WindowsInstaller value within them set to 1, if they do then we just get the name of the key (so{DJFHDFH34} for example) and pass it to our GetInstallerKeyNameFromGuid function which takes the name and works out the MSI installer ID for it (which is done by just moving some of the characters around, just look at the function to see exactly what it does). Then we look for that MSI installer ID in another part of the registry (HKEY_CLASSES_ROOT\MSI_installer_ID_here) to actually get the program name and other information.
This is the part of the code that does it (within the GetUninstallKeyPrograms method):
vb.net Code:
If Not CInt(CurrentSubKey.GetValue("WindowsInstaller", 0)) = 1 Then
'...
'... irrelevent code here
'...
Else 'If WindowsInstaller
Dim ProgVersion As String = String.Empty
Dim Name As String = String.Empty
Dim FoundName As Boolean = False
Try
Dim MsiKeyName As String = GetInstallerKeyNameFromGuid(SubKeyName)
Dim CrGuidKey As RegistryKey = ClassesKey.OpenSubKey(MsiKeyName)
If Not CrGuidKey Is Nothing Then
Name = CStr(CrGuidKey.GetValue("ProductName", String.Empty))
End If
Catch ex As Exception
Debug.WriteLine(SubKeyName & " - " & ex.Message)
End Try
Hope that explains it - I know its not very straight forward, that's why it took me ages to figure it out and get this code working 
Now it is clarified, Thanks!
-
Jun 9th, 2011, 10:29 AM
#3
Member
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
Chris,
I know that in the sub-directories in the following paths most programs have an 'installdate' key associated with them:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
Would you be able to give me some instructions on how to query the 'installdate' reg key and return that as well (similar to calling program.displayname & program.version? i.e. so I can return program.installdate
What parts of the code do I need to add to in order to be able to grab that?
I would find this very useful.
Thanks in advance, your help is always appreciated!
-Drew
-
Jun 9th, 2011, 10:45 AM
#4
Member
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
well, I think I figured it out, was easier than I thought.
Last edited by Drewster727; Jun 9th, 2011 at 11:26 AM.
-
Jun 24th, 2011, 09:11 AM
#5
Frenzied Member
Re: Example of how to get a list of installed programs (like Add and Remove Programs)
Hi Chris128, Thanks for this example works brilliantly, My code was only getting half of the apps.
I have chopped out alot of code as I didn't require it for this project as its an automated program to get details from the local machine (no updates).
It all works brilliantly I have the Target cpu set to Active (any CPU) however one small problem which isn't a big deal is the duplication of the odd few programs.
This is not a problem for us and I noticed someone else mentioned it but also mentioned it worked fine after they set it to Any CPU.
Not a problem just thought I would bring it up. But well done on the great coding :-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|