Exemplo n.º 1
0
        static bool CheckInstallerProducts(RegistryTarget searchTarget, RegistryKey searchTargetKey, string subKeyName, Product product, bool dryrun)
        {
            var targetKey = searchTargetKey.OpenSubKey(subKeyName);

            try {
                // if product code is listed in iconpath, assume a match
                var productName = (string)targetKey.GetValue("ProductName");
                var productIcon = (string)targetKey.GetValue("ProductIcon");
                targetKey.Close();
                if (productName == product.Name && productIcon.Contains(product.Key))
                {
                    // cleanup reference under Features
                    var featuresKey = RegistryKey.OpenBaseKey(searchTarget.BaseKey, RegistryView.Default).OpenSubKey(searchTarget.SubKeyName.Replace(@"\Products", @"\Features"), writable: true);
                    if (featuresKey.GetSubKeyNames().Contains(subKeyName))
                    {
                        try {
                            if (!dryrun)
                            {
                                featuresKey.DeleteSubKey(subKeyName);
                                Console.WriteLine($"Deleted {featuresKey.Name}\\{subKeyName}\\ ({product.Name} {product.Version})");
                            }
                            else
                            {
                                Console.WriteLine($"Fake Deleted {featuresKey.Name}\\{subKeyName}\\ ({product.Name} {product.Version})");
                            }
                        }
                        catch (Exception delEx) {
                            Console.WriteLine($"Error Deleting {featuresKey.Name}\\{subKeyName}\\ ({product.Name} {product.Version}) | {delEx.Message}");
                        }
                    }
                    featuresKey.Close();

                    // cleanup reference under UpgradeCodes
                    var upgradeInfoKey = RegistryKey.OpenBaseKey(searchTarget.BaseKey, RegistryView.Default).OpenSubKey(searchTarget.SubKeyName.Replace(@"\Products", @"\UpgradeCodes"), writable: true);
                    foreach (var upgradeInfoSubKeyName in upgradeInfoKey.GetSubKeyNames())
                    {
                        var subUpgradeInfoKey = upgradeInfoKey.OpenSubKey(upgradeInfoSubKeyName, writable: true);
                        if (subUpgradeInfoKey.GetValueNames().Contains(subKeyName))
                        {
                            try {
                                if (!dryrun)
                                {
                                    subUpgradeInfoKey.DeleteValue(subKeyName);
                                    Console.WriteLine($"Deleted {subUpgradeInfoKey.Name}\\{subKeyName} ({product.Name} {product.Version})");
                                }
                                else
                                {
                                    Console.WriteLine($"Fake Deleted {subUpgradeInfoKey.Name}\\{subKeyName} ({product.Name} {product.Version})");
                                }
                            }
                            catch (Exception delEx) {
                                Console.WriteLine($"Error Deleting {subUpgradeInfoKey.Name}\\{subKeyName} ({product.Name} {product.Version}) | {delEx.Message}");
                            }
                        }
                    }
                    upgradeInfoKey.Close();

                    // return true so the root key gets deleted also
                    return(true);
                }
            }
            catch { }

            // close opened key and return
            if (targetKey != null)
            {
                targetKey.Close();
            }
            return(false);
        }
Exemplo n.º 2
0
 static bool CheckProductNameOrVersion(RegistryTarget searchTarget, RegistryKey searchTargetKey, string subKeyName, Product product, bool dryrun)
 {
     return(subKeyName == product.Key || subKeyName == $"{product.Name} {product.Version}");
 }