Get the Installed Software Details of Your System in Windows Form

This article explains how to get the installed Software details of your system. Here I will get the information from the Win32_Product class.

Introduction

This article explains how to get the installed Software details
of your system. Here I will get the information from the Win32_Product class.

What Win32_Product is

The Win32_Product WMI class represents products as they are installed by Windows Installer. A product generally correlates to one installation package.

Design
 
Create a new Windows Forms Application Project.

Add one button control and one DataGrid to the form.

Design your screen as in the following screen:


Next add a reference for "System.Management".
 


To add the reference use the following procedure.

Go to Solution Explorer, select the project and right-click on that and choose "Add Reference" from the menu.



A window will open; in that choose the ".Net" tab.

3.jpg

It will show a list. In that list, choose "System.Management" and click the "OK" Button.

4.jpg

 Now go to code view

Add the namespace "using System.Management;".

Write the following code in the Button Click event
:
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
System.Management;
using
System.Globalization;
namespace
GetSoftwareDetails
{

   
public partial class Form1 : Form

   
{

       
public Form1()

       
{

           
InitializeComponent();

       
}

       
private void button1_Click(object sender, EventArgs e)

       
{

           
DataTable dt = new DataTable();

           
dt.Columns.Add(new DataColumn("Name", typeof(string)));

           
dt.Columns.Add(new DataColumn("InstallLocation", typeof(string)));

           
dt.Columns.Add(new DataColumn("Instal Date", typeof(string)));

           
dt.Columns.Add(new DataColumn("InstallState", typeof(string)));

           
dt.Columns.Add(new DataColumn("Vendor", typeof(string)));

           
dt.Columns.Add(new DataColumn("Version", typeof(string)));
            dt.Columns.Add(new DataColumn("PackageName", typeof(string)));
           
dt.Columns.Add(new DataColumn("InstallSource", typeof(string)));

           
dt.Columns.Add(new DataColumn("Language", typeof(string)));

           
dt.Columns.Add(new DataColumn("LocalPackage", typeof(string)));

           
dt.Columns.Add(new DataColumn("PackageCache", typeof(string)));

           
dt.Columns.Add(new DataColumn("PackageCode", typeof(string)));

           
dt.Columns.Add(new DataColumn("HelpTelephone", typeof(string)));

           
dt.Columns.Add(new DataColumn("AssignmentType", typeof(string)));

           
dt.Columns.Add(new DataColumn("Caption", typeof(string)));

           
dt.Columns.Add(new DataColumn("Description", typeof(string)));

           
dt.Columns.Add(new DataColumn("IdentifyingNumber", typeof(string)));

           
dt.Columns.Add(new DataColumn("ProductID", typeof(string)));

           
dt.Columns.Add(new DataColumn("RegOwner", typeof(string)));

           
dt.Columns.Add(new DataColumn("RegCompany", typeof(string)));

           
dt.Columns.Add(new DataColumn("SKUNumber", typeof(string)));

           
dt.Columns.Add(new DataColumn("Transforms", typeof(string)));

           
dt.Columns.Add(new DataColumn("URLInfoAbout", typeof(string)));

           
dt.Columns.Add(new DataColumn("URLUpdateInfo", typeof(string)));

           
dt.Columns.Add(new DataColumn("HelpLink", typeof(string)));

           
dt.Columns.Add(new DataColumn("WordCount", typeof(string)));

           
SelectQuery Sq = new SelectQuery("Win32_Product");

           
ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher(Sq);

           
ManagementObjectCollection osDetailsCollection = objOSDetails.Get();

           
foreach (ManagementObject MO in osDetailsCollection)

     
      {

               
DataRow dr = dt.NewRow();

               
dr["Name"] = MO["Name"].ToString();

               
dr["AssignmentType"] = MO["AssignmentType"].ToString();

               
dr["Caption"] = MO["Caption"];

               
dr["Description"] = MO["Description"];

               
dr["IdentifyingNumber"] = MO["IdentifyingNumber"];

               
dr["InstallLocation"] = MO["InstallLocation"];

               
var newDate = DateTime.ParseExact(MO["InstallDate"].ToString(), "yyyyMMdd", CultureInfo.InvariantCulture);

               
dr["Instal Date"] = newDate;

               
dr["InstallState"] = MO["InstallState"];

               
dr["HelpLink"] = MO["HelpLink"];

               
dr["HelpTelephone"] = MO["HelpTelephone"];

               
dr["InstallSource"] = MO["InstallSource"];

               
dr["Language"] = MO["Language"];

               
dr["LocalPackage"] = MO["LocalPackage"];

               
dr["PackageCache"] = MO["PackageCache"];

               
dr["PackageCode"] = MO["PackageCode"];

               
dr["PackageName"] = MO["PackageName"];

               
dr["InstallState"] = MO["InstallState"];

               
dr["ProductID"] = MO["ProductID"];

               
dr["RegOwner"] = MO["RegOwner"];

               
dr["RegCompany"] = MO["RegCompany"];

               
dr["SKUNumber"] = MO["SKUNumber"];

               
dr["Transforms"] = MO["Transforms"];

               
dr["URLInfoAbout"] = MO["URLInfoAbout"];

               
dr["URLUpdateInfo"] = MO["URLUpdateInfo"];

               
dr["Vendor"] = MO["Vendor"];

               
dr["WordCount"] = MO["WordCount"];

               
dr["Version"] = MO["Version"];

               
dt.Rows.Add(dr);

           
}

           
dataGridView1.DataSource = dt;

       
}

   
}

}

 

In the code above I am getting the information from Win32_Product Store the data into a data table and showing it in a DataGrid on a button click.


SelectQuery

It represents a WQL (WMI Query Language) SELECT data query.

ManagementObjectSearcher

It retrieves a collection of management objects based on a specified query.

This class is one of the more commonly used entry points to retrieving management information.

ManagementObjectCollection

It represents various collections of management objects retrieved using WMI.

Now build your application. Click on the button; just wait for 2 minute it will show the  installed Software details.


 

Thank you.