Click here to Skip to main content
15,883,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

trying to display the software installed on my machine with Name ,Version, Publisher but it displaying all data in one column.


C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace WindowsFormsApplicationTest2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string DispalyName = null;
            string RegistryKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\UnInstall";

            DataTable dt = new DataTable();
            dt.Columns.Add("Software Name", typeof(string));
            dt.Columns.Add("Software Version", typeof(string));
            dt.Columns.Add("Software Publicher", typeof(string));
            DataRow dr = null;

            using (RegistryKey RegistryKey1 = Registry.LocalMachine.OpenSubKey(RegistryKey))
            {
                if (RegistryKey1 != null)
                {
                    foreach (var varName in RegistryKey1.GetSubKeyNames())
                    {
                        using (RegistryKey RegisteyKey2 = RegistryKey1.OpenSubKey(varName))
                        {
                            if (RegisteyKey2 != null)
                            {
                                DispalyName = Convert.ToString(RegisteyKey2.GetValue("DispalyName"));
                                //if (DispalyName.Equals(""))
                                //{
                                //    continue;
                                //}
                                //else
                                //{
                                    dr = dt.NewRow();
                                    dr[0] = (string)RegisteyKey2.GetValue("DispalyName");
                                    if (RegisteyKey2.GetValue("DispalyVersion") == null || RegisteyKey2.GetValue("DispalyVersion")=="")
                                        dr[1] = "";
                                    else
                                        dr[1] = (string)RegisteyKey2.GetValue("DispalyVersion");
                                    dr[2] = (string)RegisteyKey2.GetValue("Publisher");
                                    dt.Rows.Add(dr);
                                //}
                            }
                        }
                    }
                }
            }

            GridSoftware .Columns .Clear ();
            GridSoftware .DataSource =dt;


        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}


can anyone help me to solve this query.

Thanks & Regards
sam.198979
Posted

1 solution

Instead of getting values in dr get those values in string variable and change your
C#
dt.Rows.Add(dr);

to

C#
dt.Rows.Add(drstring1,drstring2,drstring3);
 
Share this answer
 
Comments
sam.198979 18-Jun-13 6:28am    
still same problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900