Saturday, March 9, 2013

Using the wmi to get a list of installed software


Gets a list of Software installed on the local computer 

Building the Sample

Uses Visual Studio 2012 or Visual Studio 2012 Express for Windows Desktop,  The code listed below can be compiled with earlier versions of visual studio, visual basic express edition,  or c# express edition
Uses the windows managment interface and visual basic to get a list of the installed installed software on the computer.  The name of the installed software will be displayed in an windows forms list box. You can use the classes inSystem.Management to query the windows managment interface to get information about the local computer.  In this case we query the Win32_Product class to get the installed software on the computer.   The name property in the returned data is what we will display in a windows form listbox.
The Win32_Product class returns the name, install location, install date, etc..  The Win32_Product class also function for unistalling the software
   public partial class Form1 : Form 
        public Form1() 
    private void LoadSoftwareList() 
        ManagementObjectCollection moReturn;   
        ManagementObjectSearcher moSearch; 
        moSearch = new ManagementObjectSearcher("Select * from Win32_Product"); 
        moReturn = moSearch.Get(); 
       foreach(ManagementObject mo in moReturn) 
        private void Form1_Load(object sender, EventArgs e) 
Visual Basic
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
    End Sub 
    Private Sub LoadSoftwareList() 
        Dim moReturn As Management.ManagementObjectCollection 
        Dim moSearch As Management.ManagementObjectSearcher 
        Dim mo As Management.ManagementObject 
        moSearch = New Management.ManagementObjectSearcher("Select * from Win32_Product") 
        moReturn = moSearch.Get 
        For Each mo In moReturn 
    End Sub