Exemplo n.º 1
0
        public void AddOrUpdate(string Application, UninstallerRegistryConfiguration Configuration, bool DeleteNullValues = true)
        {
            var ValuesToWrite = new Dictionary <String, object>()
            {
                ["DisplayIcon"]          = Configuration.DisplayIcon,
                ["DisplayName"]          = Configuration.DisplayName,
                ["DisplayVersion"]       = Configuration.DisplayVersion,
                ["EstimatedSize"]        = Configuration.EstimatedSizeInKb,
                ["InstallDate"]          = Configuration.InstallDate?.ToString(DateFormat),
                ["InstallLocation"]      = Configuration.InstallLocation,
                ["Language"]             = Configuration.Language,
                ["NoModify"]             = Configuration.CanModify,
                ["NoRepair"]             = Configuration.CanRepair,
                ["Publisher"]            = Configuration.Publisher,
                ["QuietUninstallString"] = Configuration.QuietUninstallString,
                ["UninstallString"]      = Configuration.UninstallString,
                ["URLUpdateInfo"]        = Configuration.URLUpdateInfo,
            };

            using (var Key = RegistryKey.OpenBaseKey(Hive, View)) {
                using (var Key2 = Key.CreateSubKey(UninstallRegSubKey, true)) {
                    using (var Key3 = Key2.CreateSubKey(Application, true)) {
                        foreach (var item in ValuesToWrite)
                        {
                            var Name  = item.Key;
                            var Value = item.Value;
                            if (Value == null)
                            {
                                if (DeleteNullValues)
                                {
                                    Key3.DeleteValue(Name, false);
                                }
                            }
                            else if (Value is string)
                            {
                                Key3.SetValue(Name, Value, RegistryValueKind.String);
                            }
                            else if (Value is long || Value is CanRepairValue || Value is CanModifyValue)
                            {
                                Key3.SetValue(Name, Value, RegistryValueKind.DWord);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public UninstallerRegistryConfiguration Get(string Application)
        {
            var ret = default(UninstallerRegistryConfiguration);

            try {
                using (var Key = RegistryKey.OpenBaseKey(Hive, View)) {
                    using (var Key2 = Key.OpenSubKey(UninstallRegSubKey)) {
                        using (var Key3 = Key2.OpenSubKey(Application)) {
                            var tret = new UninstallerRegistryConfiguration()
                            {
                                DisplayIcon          = GetString(Key3, "DisplayIcon"),
                                DisplayName          = GetString(Key3, "DisplayName"),
                                DisplayVersion       = GetString(Key3, "DisplayVersion"),
                                InstallLocation      = GetString(Key3, "InstallLocation"),
                                Publisher            = GetString(Key3, "Publisher"),
                                QuietUninstallString = GetString(Key3, "QuietUninstallString"),
                                UninstallString      = GetString(Key3, "UninstallString"),
                                URLUpdateInfo        = GetString(Key3, "URLUpdateInfo"),
                                EstimatedSizeInKb    = GetLong(Key3, "EstimatedSize"),
                                Language             = GetLong(Key3, "Language"),
                                CanModify            = (CanModifyValue?)GetLong(Key3, "NoModify"),
                                CanRepair            = (CanRepairValue?)GetLong(Key3, "NoRepair"),
                                InstallDate          = GetDate(Key3, "InstallDate"),
                            };



                            ret = tret;
                        }
                    }
                }
            } catch (Exception ex) {
                ex.Ignore();
            }


            return(ret);
        }