How do i display a user's installed programs in windows forms app?

Karlo Vragotuk 1 Reputation point
2022-06-29T20:01:14.483+00:00

Hello, I am currently working on a project in windows form app. It is an advanced program manager that could display a user's installed programs and give you the option to restrict its CPU/GPU usage… However, I do not know how to make it display a user's installed programs. I have thrown together a simple sketch in paint of how I’d like it to look just so you guys can get an idea of what i have in mind. If anyone could help me that would be greatly appreciated.216240-refrence.png

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,922 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jack J Jun 24,796 Reputation points Microsoft Vendor
    2022-06-30T06:23:20.5+00:00

    @Karlo Vragotuk , Welcome to Microsoft Q&A, based on my research, I find we could use registry to get installed apps. But it is not easy to get every icons for me. Because many apps does not have their own icons.

    I make the following code to show all installed apps in the listbox and show part of icons in the listview.

     Icon ProductIcon;  
            ImageList imageListLarge = new ImageList();  
            private void button1_Click(object sender, EventArgs e)  
            {  
             
                string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";  
                int i = 0;  
                using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))  
                {  
                    foreach (string subkey_name in key.GetSubKeyNames())  
                    {  
                        using (RegistryKey subkey = key.OpenSubKey(subkey_name))  
                        {  
      
                            if (subkey.GetValue("DisplayName") != null)  
                            {  
                                //Console.WriteLine(subkey.GetValue("DisplayName"));  
                                listBox1.Items.Add(subkey.GetValue("DisplayName").ToString());  
                                if (subkey.GetValue("DisplayIcon") != null)  
                                {  
                                     
                                    Console.WriteLine(subkey.GetValue("DisplayIcon").ToString());  
      
                                    if (File.Exists(subkey.GetValue("DisplayIcon").ToString()))  
                                    {  
                                        ProductIcon = Icon.ExtractAssociatedIcon(subkey.GetValue("DisplayIcon").ToString());  
          
                                        ListViewItem item1 = new ListViewItem();  
                                        item1.SubItems.Add("item1");  
                                        item1.SubItems.Add("item2");  
                                        item1.ImageIndex = i;  
                                        listView1.Items.Add(item1);  
                                        imageListLarge.Images.Add(ProductIcon);  
                                        i++;  
                                    }  
                                    else if(subkey.GetValue("DisplayIcon").ToString().EndsWith("0"))  
                                    {  
                                        string s = subkey.GetValue("DisplayIcon").ToString().Replace(",0", "");  
                                        ProductIcon = Icon.ExtractAssociatedIcon(s.Trim());  
                                        ListViewItem item1 = new ListViewItem();  
                                        item1.SubItems.Add("item1");  
                                        item1.SubItems.Add("item2");  
                                        item1.ImageIndex = i;  
                                        listView1.Items.Add(item1);  
                                        imageListLarge.Images.Add(ProductIcon);  
                                        i++;  
      
                                    }  
      
                                }  
                                  
                            }  
                              
                        }  
                    }  
                }  
      
                listView1.SmallImageList = imageListLarge;  
      
            }  
            private void Form1_Load(object sender, EventArgs e)  
            {  
                listView1.View = View.SmallIcon;  
                // Allow the user to edit item text.  
                listView1.LabelEdit = true;  
                // Allow the user to rearrange columns.  
                listView1.AllowColumnReorder = true;  
                // Display check boxes.  
                listView1.CheckBoxes = true;  
                // Select the item and subitems when selection is made.  
                listView1.FullRowSelect = true;  
                // Display grid lines.  
                listView1.GridLines = true;  
                // Sort the items in the list in ascending order.  
                listView1.Sorting = SortOrder.Ascending;  
      
      
            }  
    

    Result:

    216356-image.png

    Hope this could help you.

    Best regards,
    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.