當前位置: 首頁>>代碼示例>>C#>>正文


C# RegistryKey.get_value_as_string方法代碼示例

本文整理匯總了C#中Microsoft.Win32.RegistryKey.get_value_as_string方法的典型用法代碼示例。如果您正苦於以下問題:C# RegistryKey.get_value_as_string方法的具體用法?C# RegistryKey.get_value_as_string怎麽用?C# RegistryKey.get_value_as_string使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.Win32.RegistryKey的用法示例。


在下文中一共展示了RegistryKey.get_value_as_string方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: evaluate_keys

        /// <summary>
        ///   Evaluates registry keys and updates the snapshop with items
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="snapshot">The snapshot.</param>
        public void evaluate_keys(RegistryKey key, Registry snapshot)
        {
            if (key == null) return;

            FaultTolerance.try_catch_with_logging_exception(
                () =>
                {
                    foreach (var subKeyName in key.GetSubKeyNames())
                    {
                        FaultTolerance.try_catch_with_logging_exception(
                            () => evaluate_keys(key.OpenSubKey(subKeyName, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey), snapshot),
                            "Failed to open subkey named '{0}' for '{1}', likely due to permissions".format_with(subKeyName, key.Name),
                            logWarningInsteadOfError: true);
                    }
                },
                "Failed to open subkeys for '{0}', likely due to permissions".format_with(key.Name),
                logWarningInsteadOfError: true);

            var appKey = new RegistryApplicationKey
                {
                    KeyPath = key.Name,
                    RegistryView = key.View,
                    DefaultValue = key.get_value_as_string(""),
                    DisplayName = key.get_value_as_string("DisplayName")
                };

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

            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;
                }

//.........這裏部分代碼省略.........
開發者ID:RichiCoder1,項目名稱:choco,代碼行數:101,代碼來源:RegistryService.cs


注:本文中的Microsoft.Win32.RegistryKey.get_value_as_string方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。