How to programmatically check for versions of software

J

Jak Sparrow

What are some good ways to programmatically check for software already
installed on a computer?

For example, to check a version of Internet Explorer, a program can check
the registry for the following value:
[HKLM\SOFTWARE\Microsoft\Internet Explorer] Version, and see if the version
is 6.0 or not.

However, not all installed software can be checked as easily. For example,
Windows Media Player 9 has the following registry path:
[HKLM\SOFTWARE\Microsoft\MediaPlayer\9.0\Registration] UDBVersion, which one
can use to see which version of WMP9 is installed. However, when version 10
does come out, one does not really know if it will use the same pattern for
registry path.

The biggest problem, perhaps, is that registry paths remain in the registry
even after a program is uninstalled. For example, one may want to check if
a program is installed simply by checking for the existence of a registry
path. But sometimes, uninstalling a program WILL NOT remove the registry
entries, and so, the program will incorrectly believe the software is
already installed.

Maybe my approach is wrong. Perhaps relying on the registry is not 100%
proof. Please suggest better ways for programmatically checking for
versions of software installed on a computer. Thanks.
 
A

Adlai Stevenson

Jak said:
What are some good ways to programmatically check for software already
installed on a computer?

For example, to check a version of Internet Explorer, a program can check
the registry for the following value:
[HKLM\SOFTWARE\Microsoft\Internet Explorer] Version, and see if the version
is 6.0 or not.

However, not all installed software can be checked as easily. For example,
Windows Media Player 9 has the following registry path:
[HKLM\SOFTWARE\Microsoft\MediaPlayer\9.0\Registration] UDBVersion, which one
can use to see which version of WMP9 is installed. However, when version 10
does come out, one does not really know if it will use the same pattern for
registry path.

The biggest problem, perhaps, is that registry paths remain in the registry
even after a program is uninstalled. For example, one may want to check if
a program is installed simply by checking for the existence of a registry
path. But sometimes, uninstalling a program WILL NOT remove the registry
entries, and so, the program will incorrectly believe the software is
already installed.

Maybe my approach is wrong. Perhaps relying on the registry is not 100%
proof. Please suggest better ways for programmatically checking for
versions of software installed on a computer. Thanks.

If you look at the file properties in Windows Explorer, you will see
that each file has a version attribute attached to it.

So

(a) Find the actual executable
(b) Use the File or FileInfo class to read the version attribute.
 
D

Daniel Pratt

Hi Jak,

Jak Sparrow said:
What are some good ways to programmatically check for software already
installed on a computer?
<snip>

WMI (System.Management namespace) is a good tool for this sort of task.
Just to give you an idea:

...
// need a "using System.Management;" somewhere
// and a reference to System.Management.dll
static void ListAllProducts()
{
SelectQuery allProductsQuery = new SelectQuery("Win32_Product");

ManagementObjectSearcher allProducts =
new ManagementObjectSearcher(allProductsQuery);

foreach(ManagementObject product in allProducts.Get())
{
Console.WriteLine("Product {0} is at version {1}",
product.Properties["Name"].Value,
product.Properties["Version"].Value);
}
}
...

Regards,
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top