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


C# RegistryKeyPermissionCheck.ToString方法代码示例

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


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

示例1: OpenRegistryKeyPath

        /// <summary>
        /// Opens and returns the RegistryKey found at the given partial registry path, starting at the given startAtKey.  Requests the given permissions.
        /// </summary>
        /// <param name="startAtKey">Gives the RegistryKey instance to start the relative traversal at, or null if the traversal should start at the root.</param>
        /// <param name="keyPathArray">Gives the partial registry key path to traverse starting at the given key, in array form.</param>
        /// <param name="permissions">Gives the RegistryKeyPermissionCheck value for the requested permissions.</param>
        /// <returns>The RegistryKey instance for the requested path.</returns>
        /// <exception cref="System.ArgumentException">If the requested regKeyPath is not valid or cannot be opened</exception>
        public static RegistryKey OpenRegistryKeyPath(this RegistryKey startAtKey, string[] keyPathArray, RegistryKeyPermissionCheck permissions)
        {
            RegistryKey currentKey = startAtKey;
            bool preventDisposeCurrentKey = true;       // it came from the one we were given on call

            try
            {
                RegistryKey nextKey = null;

                if (keyPathArray == null)
                    throw new System.ArgumentNullException("keyPathArray");
                else if (keyPathArray.Length == 0)
                    throw new System.ArgumentException("must have at least one element", "keyPathArray");

                int keyIdx = 0;

                if (currentKey == null)
                {
                    currentKey = GetRegistryHiveKey(keyPathArray[keyIdx++]);
                    preventDisposeCurrentKey = true;        // it came from the GetRegistryHiveKey method (static key)
                }

                for (; keyIdx < keyPathArray.Length; keyIdx++)
                {
                    string keyName = keyPathArray[keyIdx];

                    if (permissions == RegistryKeyPermissionCheck.ReadWriteSubTree)
                    {
                        nextKey = currentKey.OpenSubKey(keyName, permissions);
                        if (nextKey == null)
                            nextKey = currentKey.CreateSubKey(keyName, permissions);
                        if (nextKey == null)
                            throw new System.ArgumentException(Utils.Fcns.CheckedFormat("Unable to create key:{0} under path:{1}, {2}", keyName, currentKey.ToString(), permissions.ToString()), Utils.Fcns.CheckedFormat("keyPathArray[{0}]", keyIdx));
                    }
                    else
                    {
                        nextKey = currentKey.OpenSubKey(keyName, permissions);
                        if (nextKey == null)
                            throw new System.ArgumentException(Utils.Fcns.CheckedFormat("Unable to open key:{0} under path:{1}, {2}", keyName, currentKey.ToString(), permissions.ToString()), Utils.Fcns.CheckedFormat("keyPathArray[{0}]", keyIdx));
                    }

                    if (!preventDisposeCurrentKey)
                        Utils.Fcns.DisposeOfObject(ref currentKey);

                    currentKey = nextKey;
                    preventDisposeCurrentKey = false;       // it comes from one that was opened above so we can dispose it if it is not the one we will actually return.
                }

                return currentKey;
            }
            catch
            {
                // will re-throw the original exception after disposing of any intermediate key
                if (!preventDisposeCurrentKey && currentKey != null)
                    Utils.Fcns.DisposeOfObject(ref currentKey);

                throw;
            }
        }
开发者ID:mosaicsys,项目名称:MosaicLibCS,代码行数:67,代码来源:Registry.cs


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