예제 #1
0
        /// <summary>
        ///     Tries to opens a subkey.
        ///     Will handle multi-level names, such as "Software\SubKey\Subkey2\"
        /// </summary>
        /// <param name="name">Name of the subkey to open.</param>
        /// <param name="key">The newly opened subkey</param>
        /// <returns>True if the operation was sucessful, false otherwise.</returns>
        public bool TryOpenSubKey(string name, out OffregKey key)
        {
            IntPtr      childPtr;
            Win32Result result = OffregNative.OpenKey(_intPtr, name, out childPtr);

            if (result != Win32Result.ERROR_SUCCESS)
            {
                key = null;
                return(false);
            }

            key = new OffregKey(this, childPtr, name);
            return(true);
        }
예제 #2
0
        /// <summary>
        ///     Constructor, opens a subkey.
        /// </summary>
        /// <param name="parentKey">The parent key.</param>
        /// <param name="name">The name of the subkey to open.</param>
        internal OffregKey(OffregKey parentKey, string name)
        {
            Win32Result result = OffregNative.OpenKey(parentKey._intPtr, name, out _intPtr);

            if (result != Win32Result.ERROR_SUCCESS)
            {
                throw new Win32Exception((int)result);
            }

            Name     = name;
            FullName = (parentKey.FullName == null ? "" : parentKey.FullName + "\\") + name;
            _parent  = parentKey;

            _metadata = new QueryInfoKeyData();
            RefreshMetadata();
        }
예제 #3
0
        /// <summary>
        ///     Detect if a subkey exists in this key.
        /// </summary>
        /// <param name="name">The subkey to find</param>
        /// <returns>True if it exists, false otherwise.</returns>
        public bool SubkeyExist(string name)
        {
            IntPtr intPtr = IntPtr.Zero;

            try
            {
                Win32Result result = OffregNative.OpenKey(_intPtr, name, out intPtr);

                return(result == Win32Result.ERROR_SUCCESS);
            }
            finally
            {
                // Close up shop
                if (intPtr != IntPtr.Zero)
                {
                    OffregNative.CloseKey(intPtr);
                }
            }
        }