public FakeInstalledProductsFinder(params ProductInstallationMetaData[] metaData)
 {
     foreach (var element in metaData)
     {
         InstalledProducts.Add(element);
     }
 }
Example #2
0
        public static IEnumerable FindProductInstallations(string productSearchPattern, string fileSearchPattern)
        {
            var installs = new InstalledProducts();

            installs.LookUpAndInitProducts(new InstalledProductLookUp(productSearchPattern, fileSearchPattern));

            return
                (installs.Products.Select(
                     p =>
                     new KeyValuePair <string, Tuple <int, int, int, int> >(
                         p.InstallLocation,
                         p.VersionInfo)));
        }
Example #3
0
        public void GetInstalledProducts()
        {
            var products = new Dictionary <string, Tuple <int, int, int, int> >
            {
                { "A", Tuple.Create(0, 1, 2, 3) },
                { "B", Tuple.Create(0, 1, 3, 4) },
                { "C", Tuple.Create(1, 2, 3, 4) },
                { "D", Tuple.Create(1, 0, 3, 4) },
                { "E", null }
            };
            var lookUp = SetUpProductLookUp(products, null);

            var p = new InstalledProducts();

            p.LookUpAndInitProducts(lookUp);

            Assert.AreEqual("C", p.GetLatestProduct().ProductName);
            Assert.AreEqual("1.2.3.4", p.GetLatestProduct().VersionString);
            Assert.AreEqual(4, p.Products.Count());
        }
        /// <summary>
        /// Load Office Configuration information
        /// </summary>
        public OfficeConfiguration()
        {
            RegistryKey localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);

            try
            {
                RegistryKey subKey = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\ClickToRun\Configuration");
                if (subKey == null)
                {
                    localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
                    subKey   = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\ClickToRun\Configuration");
                    if (subKey == null)
                    {
                        return;
                    }
                }
                object h = subKey.GetValue("InstallationPath");
                if (h != null)
                {
                    InstallPath = h.ToString();
                }
                h = subKey.GetValue("ClientVersionToReport");
                if (h != null)
                {
                    string registData = h.ToString();
                    ClickToRunVersion = registData;
                }
                h = subKey.GetValue("UpdateChannelChanged");
                if (h != null)
                {
                    if (h.ToString() == "True")
                    {
                        ChannelChanged = true;
                    }
                    else
                    {
                        ChannelChanged = false;
                    }
                }
                else
                {
                    ChannelChanged = false;
                }
                h = subKey.GetValue("Platform");
                if (h != null)
                {
                    OfficePlatform = h.ToString();
                }
                h = subKey.GetValue("ClientCulture");
                if (h != null)
                {
                    ClickToRunLanguage = h.ToString();
                    Languages          = new List <string>
                    {
                        ClickToRunLanguage
                    };
                }
                h = subKey.GetValue("ClientFolder");
                if (h != null)
                {
                    ClickToRunPath = h.ToString();
                }
                h = subKey.GetValue("UpdateChannel");
                if (h != null)
                {
                    string registData = h.ToString().ToLower();
                    UpdateChannel = registData;
                }
                h = subKey.GetValue("ProductReleaseIds");
                if (h != null)
                {
                    // Get the all installed products
                    string registData = h.ToString();
                    subKey = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\ClickToRun\Configuration");

                    RegistryKey tempKey = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\ClickToRun\ProductReleaseIDs");
                    string      path    = tempKey.GetValue("ActiveConfiguration").ToString();
                    tempKey = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\ClickToRun\ProductReleaseIDs\" + path);
                    // Foreach all installed products information
                    foreach (string id in registData.Split(','))
                    {
                        string excludeApps = string.Empty;
                        string owner       = string.Empty;
                        string version     = string.Empty;

                        h = subKey.GetValue(id + ".ExcludedApps");
                        if (h != null)
                        {
                            excludeApps = h.ToString();
                        }
                        h = subKey.GetValue(id + ".EmailAddress");
                        if (h != null)
                        {
                            owner = h.ToString();
                        }

                        foreach (string s in tempKey.GetSubKeyNames())
                        {
                            if (s.Contains(id))
                            {
                                RegistryKey temp = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\ClickToRun\ProductReleaseIDs\" + path + @"\" + s);
                                foreach (string lang in temp.GetSubKeyNames())
                                {
                                    if (!lang.Contains("x-none"))
                                    {
                                        if (!Languages.Contains(lang))
                                        {
                                            Languages.Add(lang);
                                        }
                                    }
                                    else if (lang.Contains("x-none"))
                                    {
                                        temp = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Office\ClickToRun\ProductReleaseIDs\" + path + @"\" + s + @"\" + lang);
                                        if ((h = temp.GetValue("Version")) != null)
                                        {
                                            version = h.ToString();
                                        }
                                    }
                                }
                            }
                        }

                        InstalledProducts products = new InstalledProducts(id, excludeApps, owner, version);
                        InstalledProductsList.Add(products);
                        HasOffice = true;
                    }
                }
                subKey.Close();
            }
            catch
            {
                throw;
            }
            finally
            {
                localKey.Close();
            }
        }
Example #5
0
 public FakeInstalledProductsFinder(params ProductInstallationMetaData[] metaData)
 {
     InstalledProducts.AddRange(metaData);
 }