当前位置: 首页>>代码示例>>C#>>正文


C# RegistryKey.Dispose方法代码示例

本文整理汇总了C#中Microsoft.Win32.RegistryKey.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# RegistryKey.Dispose方法的具体用法?C# RegistryKey.Dispose怎么用?C# RegistryKey.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Win32.RegistryKey的用法示例。


在下文中一共展示了RegistryKey.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: evaluate_keys


//.........这里部分代码省略.........
            }

            if (!string.IsNullOrWhiteSpace(appKey.DisplayName))
            {
                appKey.InstallLocation = key.get_value_as_string("InstallLocation");
                appKey.UninstallString = key.get_value_as_string("UninstallString");
                if (!string.IsNullOrWhiteSpace(key.get_value_as_string("QuietUninstallString")))
                {
                    appKey.UninstallString = key.get_value_as_string("QuietUninstallString");
                    appKey.HasQuietUninstall = true;
                }

                // informational
                appKey.Publisher = key.get_value_as_string("Publisher");
                appKey.InstallDate = key.get_value_as_string("InstallDate");
                appKey.InstallSource = key.get_value_as_string("InstallSource");
                appKey.Language = key.get_value_as_string("Language");

                // Version
                appKey.DisplayVersion = key.get_value_as_string("DisplayVersion");
                appKey.Version = key.get_value_as_string("Version");
                appKey.VersionMajor = key.get_value_as_string("VersionMajor");
                appKey.VersionMinor = key.get_value_as_string("VersionMinor");

                // installinformation
                appKey.SystemComponent = key.get_value_as_string("SystemComponent") == "1";
                appKey.WindowsInstaller = key.get_value_as_string("WindowsInstaller") == "1";
                appKey.NoRemove = key.get_value_as_string("NoRemove") == "1";
                appKey.NoModify = key.get_value_as_string("NoModify") == "1";
                appKey.NoRepair = key.get_value_as_string("NoRepair") == "1";
                appKey.ReleaseType = key.get_value_as_string("ReleaseType");
                appKey.ParentKeyName = key.get_value_as_string("ParentKeyName");

                if (appKey.WindowsInstaller || appKey.UninstallString.to_string().to_lower().Contains("msiexec"))
                {
                    appKey.InstallerType = InstallerType.Msi;
                }

                if (key.Name.EndsWith("_is1") || !string.IsNullOrWhiteSpace(key.get_value_as_string("Inno Setup: Setup Version")))
                {
                    appKey.InstallerType = InstallerType.InnoSetup;
                }

                if (!string.IsNullOrWhiteSpace(key.get_value_as_string("dwVersionMajor")))
                {
                    appKey.InstallerType = InstallerType.Nsis;
                    appKey.VersionMajor = key.get_value_as_string("dwVersionMajor");
                    appKey.VersionMinor = key.get_value_as_string("dwVersionMinor");
                    appKey.VersionRevision = key.get_value_as_string("dwVersionRev");
                    appKey.VersionBuild = key.get_value_as_string("dwVersionBuild");
                }
                if (appKey.ReleaseType.is_equal_to("Hotfix") || appKey.ReleaseType.is_equal_to("Update Rollup") || appKey.ReleaseType.is_equal_to("Security Update") || appKey.DefaultValue.to_string().StartsWith("KB", ignoreCase: true, culture: CultureInfo.InvariantCulture))
                {
                    appKey.InstallerType = InstallerType.HotfixOrSecurityUpdate;
                }
                if (appKey.ReleaseType.is_equal_to("ServicePack"))
                {
                    appKey.InstallerType = InstallerType.ServicePack;
                }

                // assume NSIS if we still don't know and we find uninst.exe
                if (appKey.InstallerType == InstallerType.Unknown && appKey.UninstallString.to_string().to_lower().Contains("uninst.exe"))
                {
                    appKey.InstallerType = InstallerType.Nsis;
                }

                if (appKey.InstallerType == InstallerType.Unknown && appKey.HasQuietUninstall)
                {
                    appKey.InstallerType = InstallerType.Custom;
                }

                if (appKey.InstallerType == InstallerType.Msi)
                {
                    get_msi_information(appKey, key);
                }

                if (_logOutput)
                {
                    //if (appKey.is_in_programs_and_features() && appKey.InstallerType == InstallerType.Unknown)
                    //{
                        foreach (var name in key.GetValueNames())
                        {
                            //var kind = key.GetValueKind(name);
                            var value = key.get_value_as_string(name);
                            if (name.is_equal_to("QuietUninstallString") || name.is_equal_to("UninstallString"))
                            {
                                Console.WriteLine("key - {0}|{1}={2}|Type detected={3}|install location={4}".format_with(key.Name, name, value.to_string(), appKey.InstallerType.to_string(),appKey.InstallLocation.to_string()));
                            }

                            //Console.WriteLine("key - {0}, name - {1}, kind - {2}, value - {3}".format_with(key.Name, name, kind, value.to_string()));
                        }
                    //}
                }

                snapshot.RegistryKeys.Add(appKey);
            }

            key.Close();
            key.Dispose();
        }
开发者ID:RichiCoder1,项目名称:choco,代码行数:101,代码来源:RegistryService.cs

示例2: evaluate_keys


//.........这里部分代码省略.........
            var appKey = new RegistryApplicationKey
                {
                    KeyPath = key.Name,
                    RegistryView = key.View,
                    DefaultValue = key.GetValue("").to_string(),
                    DisplayName = key.GetValue("DisplayName").to_string()
                };

            if (string.IsNullOrWhiteSpace(appKey.DisplayName))
            {
                appKey.DisplayName = appKey.DefaultValue;
            }

            if (!string.IsNullOrWhiteSpace(appKey.DisplayName))
            {
                appKey.InstallLocation = key.GetValue("InstallLocation").to_string();
                appKey.UninstallString = key.GetValue("UninstallString").to_string();
                if (key.GetValue("QuietUninstallString") != null)
                {
                    appKey.UninstallString = key.GetValue("QuietUninstallString").to_string();
                    appKey.HasQuietUninstall = true;
                }

                // informational
                appKey.Publisher = key.GetValue("Publisher").to_string();
                appKey.InstallDate = key.GetValue("InstallDate").to_string();
                appKey.InstallSource = key.GetValue("InstallSource").to_string();
                appKey.Language = key.GetValue("Language").to_string();

                // Version
                appKey.DisplayVersion = key.GetValue("DisplayVersion").to_string();
                appKey.Version = key.GetValue("Version").to_string();
                appKey.VersionMajor = key.GetValue("VersionMajor").to_string();
                appKey.VersionMinor = key.GetValue("VersionMinor").to_string();

                // installinformation
                appKey.SystemComponent = key.GetValue("SystemComponent").to_string() == "1";
                appKey.WindowsInstaller = key.GetValue("WindowsInstaller").to_string() == "1";
                appKey.NoRemove = key.GetValue("NoRemove").to_string() == "1";
                appKey.NoModify = key.GetValue("NoModify").to_string() == "1";
                appKey.NoRepair = key.GetValue("NoRepair").to_string() == "1";
                appKey.ReleaseType = key.GetValue("ReleaseType").to_string();
                appKey.ParentKeyName = key.GetValue("ParentKeyName").to_string();

                if (appKey.WindowsInstaller || appKey.UninstallString.to_lower().Contains("msiexec"))
                {
                    appKey.InstallerType = InstallerType.Msi;
                }

                if (key.Name.EndsWith("_is1") || !string.IsNullOrWhiteSpace(key.GetValue("Inno Setup: Setup Version").to_string()))
                {
                    appKey.InstallerType = InstallerType.InnoSetup;
                }

                if (key.GetValue("dwVersionMajor") != null)
                {
                    appKey.InstallerType = InstallerType.Nsis;
                    appKey.VersionMajor = key.GetValue("dwVersionMajor").to_string();
                    appKey.VersionMinor = key.GetValue("dwVersionMinor").to_string();
                    appKey.VersionRevision = key.GetValue("dwVersionRev").to_string();
                    appKey.VersionBuild = key.GetValue("dwVersionBuild").to_string();
                }
                if (appKey.ReleaseType.is_equal_to("Hotfix") || appKey.ReleaseType.is_equal_to("Update Rollup") || appKey.ReleaseType.is_equal_to("Security Update") || appKey.DefaultValue.to_string().StartsWith("KB", ignoreCase: true, culture: CultureInfo.InvariantCulture))
                {
                    appKey.InstallerType = InstallerType.HotfixOrSecurityUpdate;
                }
                if (appKey.ReleaseType.is_equal_to("ServicePack"))
                {
                    appKey.InstallerType = InstallerType.ServicePack;
                }

                if (appKey.InstallerType == InstallerType.Unknown && appKey.HasQuietUninstall)
                {
                    appKey.InstallerType = InstallerType.Custom;
                }

                if (_logOutput)
                {
                    if (appKey.is_in_programs_and_features() && appKey.InstallerType == InstallerType.Unknown)
                    {
                        foreach (var name in key.GetValueNames())
                        {
                            //var kind = key.GetValueKind(name);
                            var value = key.GetValue(name);
                            if (name.is_equal_to("QuietUninstallString") || name.is_equal_to("UninstallString"))
                            {
                                Console.WriteLine("key - {0}|{1}={2}|Type detected={3}".format_with(key.Name, name, value.to_string(), appKey.InstallerType.to_string()));
                            }

                            //Console.WriteLine("key - {0}, name - {1}, kind - {2}, value - {3}".format_with(key.Name, name, kind, value.to_string()));
                        }
                    }
                }

                snapshot.RegistryKeys.Add(appKey);
            }

            key.Close();
            key.Dispose();
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:101,代码来源:RegistryService.cs


注:本文中的Microsoft.Win32.RegistryKey.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。