Пример #1
0
        /// <summary>
        ///     Detect if a value exists in this key.
        /// </summary>
        /// <param name="name">The value to find</param>
        /// <returns>True if it exists, false otherwise.</returns>
        public bool ValueExist(string name)
        {
            RegValueType type;
            uint         size   = 0;
            Win32Result  result = OffregNative.GetValue(_intPtr, null, name, out type, IntPtr.Zero, ref size);

            return(result == Win32Result.ERROR_SUCCESS);
        }
Пример #2
0
        /// <summary>
        ///     Gets the type of a single value.
        /// </summary>
        /// <param name="name">The name of the value to retrieve the type of.</param>
        /// <returns>The type of the value.</returns>
        public RegValueType GetValueKind(string name)
        {
            RegValueType type;

            Win32Result result = OffregNative.GetValue(_intPtr, null, name, out type, IntPtr.Zero, IntPtr.Zero);

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

            return(type);
        }
Пример #3
0
        /// <summary>
        ///     Internal helper to get the type and data for a specified value.
        /// </summary>
        /// <param name="name">The name of the value to retrieve data for.</param>
        /// <returns>The type and data for the specified value.</returns>
        internal Tuple <RegValueType, byte[]> GetValueInternal(string name)
        {
            RegValueType type;

            // Get the size first
            uint        size   = 0;
            Win32Result result = OffregNative.GetValue(_intPtr, null, name, out type, IntPtr.Zero, ref size);

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

            // Allocate buffer
            byte[] res     = new byte[size];
            IntPtr dataPtr = IntPtr.Zero;

            try
            {
                dataPtr = Marshal.AllocHGlobal((int)size);

                // Get data
                result = OffregNative.GetValue(_intPtr, null, name, out type, dataPtr, ref size);

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

                // Copy data
                Marshal.Copy(dataPtr, res, 0, (int)size);
            }
            finally
            {
                // Release data
                if (dataPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(dataPtr);
                }
            }

            return(new Tuple <RegValueType, byte[]>(type, res));
        }