0

I'm building an asset tracker of sorts. I'm already searching the registry to get a list of all software titles, publishers, install dates and it's working great. However, programs installed with ClickOnce don't store the install date in the registry(at least not that I can find).

I know I should eb able to use WMI to get the install date, but this is very slow. Also, per this post: Get installed applications in a system "using the WMI Win32_Product class is a bad idea if you plan to run this query repeatedly"

So, without using WMI, how can I get the install date of ClickOnce programs? I know the information is available somehow because the date is inside of Add/Remove programs.

Community
  • 1
  • 1
Brandon
  • 1,058
  • 1
  • 18
  • 42
  • See http://stackoverflow.com/questions/18679441/where-does-add-remove-programs-pull-data-for-the-installed-on-column – William Oct 15 '13 at 16:17
  • @William That post seems to suggest that the cleanest way would be to query WMI. Is there a way to query WMI for a specific program? I'm hoping to avoid looping through 300 installed programs. I've even tried a ManagementObjectSearcher select statement, but even that query has a long response time. – Brandon Oct 18 '13 at 00:19
  • I linked it because it indicates how the install date is determined for apps that do not have an installed date registry value. The answer lists the steps to determine install date. – William Oct 18 '13 at 01:19
  • Just FYI, this information is not retained or stored by the ClickOnce framework. – RobinDotNet Oct 18 '13 at 18:26

1 Answers1

0

As ClickOnce application installs per user, you can find uninstall information (what app wizard shows you) by follwing path in registry:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\5f7eb300e2ea4ebf

This 'Uninstall' has unique hash subkeys, to find your app you can iterate through these keys and filter for example by DisplayName like this:

private RegistryKey GetUninstallRegistryKeyByProductName(string productName)
{
        var subKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
        if (subKey == null)
            return null;
        foreach (var name in subKey.GetSubKeyNames())
        {
            var application = subKey.OpenSubKey(name, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.QueryValues | RegistryRights.ReadKey | RegistryRights.SetValue);
            if (application == null)
                continue;
            foreach (var appKey in application.GetValueNames().Where(appKey => appKey.Equals("DisplayName")))
            {
                if (application.GetValue(appKey).Equals(productName))
                    return application;
                break;
            }
        }
        return null;
    }

This method returns RegistryKey, then you can get 'DisplayVersion' key value:

var key = GetUninstallRegistryKeyByProductName("myApp");
var version = key.GetValue("DisplayVersion");

Update

Regarding Install date, Try getting last write time of registry key (Getting last write time of "DisplayVersion" is what you need). It looks like there's no managed wrapper for getting this, so use P/Invoke. You need to call RegQueryInfoKey.

Community
  • 1
  • 1
Ivan Leonenko
  • 2,363
  • 2
  • 27
  • 37
  • Right, this is what I'm doing currently. I don't think this addresses my question about getting the install date of ClickOnce programs. You'll notice that ClickOnce programs don't store the install date in the registry. – Brandon Oct 18 '13 at 00:16
  • I updated the answer, don't know why I answered about the version. – Ivan Leonenko Oct 18 '13 at 06:00