1

I am using below code to get list of installed software, i am able to get installation date for around 90% software but for around 10% software, i am getting blank in installation date (even though the installdate is present in their registry key)

key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
    foreach (String keyName in key.GetSubKeyNames())
    {
       RegistryKey subkey = key.OpenSubKey(keyName);
       string appname = subkey.GetValue("DisplayName") as string;
       string Vendor_Publisher = Convert.ToString(subkey.GetValue("Publisher"));
       string Version = Convert.ToString(subkey.GetValue("DisplayVersion"));
       string InstallDate = Convert.ToString(subkey.GetValue("InstallDate"));
    }

The application is installed on windows 7 (32-bit) InstallDate

Dr. Rajesh Rolen
  • 14,029
  • 41
  • 106
  • 178

1 Answers1

0

What i have found that... All keys may not be present for all entry in the registry. So my suggestion is to check whether that key is present or not :
You can registry entry with `subkey.GetValueNames():

string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using (Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
{
    RegistryKey subkey = null;
    try
    {
        foreach (string subkey_name in key.GetSubKeyNames())
        {
            subkey = key.OpenSubKey(subkey_name);

        string[] columns = subkey.GetValueNames();
        string appname = subkey.GetValue("DisplayName") as string;
        string Vendor_Publisher = Convert.ToString(subkey.GetValue("Publisher"));
        string Version = Convert.ToString(subkey.GetValue("DisplayVersion"));
        if (columns.Contains("InstallDate"))
        {
            string InstallDate = Convert.ToString(subkey.GetValue("InstallDate"));
        }

    }
 }
catch (Exception ex)
 {
    throw ex;
 }
}

You can put the check for all the entries you are reading.

Mohammad Arshad Alam
  • 9,694
  • 6
  • 38
  • 61