Results 1 to 40 of 103

Thread: Example of how to get a list of installed programs (like Add and Remove Programs)

Hybrid View

  1. #1

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Quote Originally Posted by Blagojce View Post
    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:
    1. If Not CInt(CurrentSubKey.GetValue("WindowsInstaller", 0)) = 1 Then
    2. '...
    3. '... irrelevent code here
    4. '...
    5. Else   'If WindowsInstaller
    6.      Dim ProgVersion As String = String.Empty
    7.      Dim Name As String = String.Empty
    8.      Dim FoundName As Boolean = False
    9.      Try
    10.            Dim MsiKeyName As String = GetInstallerKeyNameFromGuid(SubKeyName)
    11.            Dim CrGuidKey As RegistryKey = ClassesKey.OpenSubKey(MsiKeyName)
    12.            If Not CrGuidKey Is Nothing Then
    13.                   Name = CStr(CrGuidKey.GetValue("ProductName", String.Empty))
    14.            End If
    15.      Catch ex As Exception
    16.            Debug.WriteLine(SubKeyName & " - " & ex.Message)
    17.      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
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  2. #2
    Addicted Member
    Join Date
    Sep 2008
    Posts
    149

    Re: Example of how to get a list of installed programs (like Add and Remove Programs)

    Quote Originally Posted by chris128 View Post
    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:
    1. If Not CInt(CurrentSubKey.GetValue("WindowsInstaller", 0)) = 1 Then
    2. '...
    3. '... irrelevent code here
    4. '...
    5. Else   'If WindowsInstaller
    6.      Dim ProgVersion As String = String.Empty
    7.      Dim Name As String = String.Empty
    8.      Dim FoundName As Boolean = False
    9.      Try
    10.            Dim MsiKeyName As String = GetInstallerKeyNameFromGuid(SubKeyName)
    11.            Dim CrGuidKey As RegistryKey = ClassesKey.OpenSubKey(MsiKeyName)
    12.            If Not CrGuidKey Is Nothing Then
    13.                   Name = CStr(CrGuidKey.GetValue("ProductName", String.Empty))
    14.            End If
    15.      Catch ex As Exception
    16.            Debug.WriteLine(SubKeyName & " - " & ex.Message)
    17.      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!

  3. #3
    Member
    Join Date
    Feb 2010
    Posts
    36

    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

  4. #4
    Member
    Join Date
    Feb 2010
    Posts
    36

    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.

  5. #5
    Frenzied Member
    Join Date
    Sep 2006
    Location
    UK / East Sussex
    Posts
    1,054

    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 :-)
    M.Carpenter

    Server Admin for Wurm Online
    Wurm Online - A very unique and original MMO from Code Club AB
    https://www.youtube.com/watch?v=YQlYar2uHWAWurm Trailor


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