Add UninstallString to Hardware Inventory

Version: SCCM 2012 SP1 CU2

Note: If you upgrade to SCCM 2012 R2, you may need to repeat Part 1 again if previously configured.

The following method can be used to add the “UninstallString” to Hardware Inventory for each application installed on client machines. This could be helpful to gather MSI product codes if you need to remove several applications via script or software distribution methods.

By default, SCCM does hardware inventory (when enabled) on the following registry keys within the Uninstall section: ProductID (ProdID), DisplayName, InstallDate, Publisher, DisplayVersion. However, the “UninstallString” is not inventoried by default. This registry value is found under the following locations.

Default location under 32-bit and 64-bit operating systems:

  • HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\UninstallString

Default location under 64-bit operating systems for 32-bit apps:

  • HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\UninstallString

In order to inventory these registry values, there are 2 areas that require modification.

  1. Modifying Hardware Inventory reporting classes under Client Settings.
  2. Modifying the configuration.mof

Part 1 – Modifying Hardware Inventory Reporting Classes (instructing clients to report)

Within the CM console, navigate to Administration -> Client Settings. Right-click on “Default Client Settings” and select properties.

SR11-22-1

Select Hardware Inventory and click on “Set Classes”.

SR11-22-2

Expand the “Installed Applications” categories. There should be two classes for 32 and 64 bit apps. Notice carefully that there is no “UninstallString” property to place a checkmark. We need to first add this property to the existing reporting classes. In SCCM 2007, this would be accomplished by modifying the SMS_DEF.mof file. However, this file does not exist in SCCM 2012. Instead, we’ll take a slightly different approach. But, the concept should be the same.

Click the “Export” button and save a copy of the exported file as “Before.mof”.

SR11-22-3

Make a copy of the Before.mof file and save it as After.mof. Then open the After.mof using Notepad.

Locate the Win32Reg_AddRemoveProgram64 and Win32Reg_AddRemoveProgram32 reporting classes. For each class, add the following lines:

    [ SMS_Report (TRUE) ]
    String     UninstallString;

See the following example image.

SR11-22-10

Save and close the After.mof file. Go back to Hardware Inventory Classes in the CM console and click the “Import” button.

SR11-22-5

Locate and select the After.mof file. Click the Open button to import.

SR11-22-6

You can leave the default to “Import both hardware inventory classes and hardware inventory class settings”. We’ve only made a slight change to two hardware inventory classes. The import process will ignore anything else that remains the same.

Before clicking the Import button on this screen, scroll down to the bottom.

SR11-22-7

You will notice the only changes made will be the two hardware inventory classes modified.

Click Import.

SR11-22-8

Now, there will be an “UninstallString” property for both classes in the console.

SR11-22-4

Optionally, WMI can be inspected via PowerShell from the site server. Verify Win32_AddRemovePrograms and Win32_AddRemovePrograms64 under the “root\cimv2\sms\inv_temp” namespace now have the “UninstallString”  within it’s properties. This is verifying that the site server has correctly changed the reporting classes for hardware inventory within it’s own WMI.

From the SCCM site server using the Powershell command prompt:

(Get-WmiObject -class Win32Reg_AddRemovePrograms -Namespace “root\cimv2\sms\inv_temp” -list | select properties).properties | Where-Object {$_.Name -eq “UninstallString”}

(Get-WmiObject -class Win32Reg_AddRemovePrograms64 -Namespace “root\cimv2\sms\inv_temp” -list | select properties).properties | Where-Object {$_.Name -eq “UninstallString”}

SR11-22-11

At this point, we have instructed SCCM to modify it’s hardware inventory policy to collect WMI class data from client machines. Specifically, we are asking clients to include an additional property called “UninstallString” when reporting WMI classes Win32Reg_AddRemovePrograms and Win32Reg_AddRemovePrograms64 from the “root\cimv2” namespace.

Clients already report these classes by default when hardware inventory is enabled. However, now it will also gather the “UninstallString” property (if it exist locally, but this class property does not exist quite yet on client machines).

The next part describes instructing clients to begin storing the “UninstallString” within WMI locally. Notice the difference between “instructing clients on reporting” versus “instructing clients to store locally in WMI”.

Part 2 – Modifying Configuration.mof (instructing clients to store locally in WMI)

Navigate to the location of the configuration.mof on your site server. This is typically in the following location;

<SCCM install path>\inboxes\clifiles.src\hinv

First, make a backup copy of the existing configuration.mof file. Next, edit the existing file using Notepad. I recommend making the edit change from a temporary location in case you make multiple saves.

Locate the Win32Reg_AddRemovePrograms and Win32Reg_AddRemovePrograms64 classes in the configuration.mof.  Add the following lines to each class:

    [PropertyContext(“UninstallString”)]
        string    UninstallString;

See the following example image.

SR11-22-12

Once this file is saved, SCCM will process this new file for clients to begin downloading. Upon downloading, clients will compile the new configuration.mof.

After sufficient time has passed, you can optionally inspect WMI using Powershell on any SCCM client machine.

Get-WmiObject Win32Reg_AddRemovePrograms | Get-Member
Get-WmiObject Win32Reg_AddRemovePrograms64 | Get-Member

SR11-22-13

As clients send hardware inventory, you can create reports on data by using the following views in the CM SQL database:

  • v_GS_ADD_REMOVE_PROGRAMS
  • v_GS_ADD_REMOVE_PROGRAMS64

The uninstall strings will be stored under the “UninstallString0” column.