Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Comparing Computer Information with WMI, Part II-2 : Page 2

What Does it Mean to Install?
In the first version of this code, I used the WMI method Win32_Product to retrieve all software, but "all" isn't really all—it's all the software installed with MSI (Microsoft Windows Installer). A rather large number of installations still don't use this technology. If you really want to look at all the installed programs, you will need to look in the registry. This is one of the three new menu options I've provided in this version (see Figure 1).

Figure 1. Three New Selections: There are three new menu items available in this version of the program. These new options allow you to get all the installed software (not just MSI installed), get the Quick Fixes via WMI, or get the Quick Fixes via the registry.
The code behind the new menu item is in the GetInstalledSoftwareData2 function. One of the curious things about this function is that instead of using the SWbemServices object already set as in the other methods, I set a new object using a root of "root/default:StdRegProv". That is because the registry provider doesn't fit into the standard WMI hierarchy under root/cimv2 namespace, so it exists in it's own namespace. Using WMI (instead of using the Windows API functions to access the remote registry functions) has both advantages and disadvantages. The disadvantages are fairly obvious—the remote computer must have WMI installed, and using WMI is one more "layer" you have to deal with in your code. However, the advantages are real. The primary advantage is that WMI has a fairly consistent set of objects and object access methods, as well as a standard set of security methods, and this consistency is a useful thing while programming.

Figure 2. Get All the Software: If you use the WMI method to determine the installed software, you get only that software that used Microsoft's underlying MSI methods for installation. Using a registry call (from WMI), you can get all the installed software.
Using the registry allows you to get all the information about installed programs. However, since the programs were installed by multiple methods, the actual values that exist in the registry for a particular installation vary with the installation program. So, for getting the display name, you look first at "DisplayName" value, then the "QuietDisplayName", and, finally, at the name of the key which is the root of these values. For the version, you look at the "DisplayVersion", then the concatenation of "VersionMajor" and "VersionMinor", or, finally, the "Version" value. For the installation location, look first at "InstallLocation", and if that value isn't present, look for the "UninstallString" value. This value is almost always located in the installation directory. At the very least, the installation directory will give you a hint as to where the program was installed.

Only add the entries where you found some non-blank entry for the display name. Note that by writing your own code, you gain quite a bit of flexibility in information retrieval, without too much extra pain (see Figure 2). For example, MSI installations will have the InstallatLocation values, and most pre-MSI installs will have the "UninstallString" value present (see Listing 1).

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date