Esempio n. 1
0
        /// <summary>
        ///     Sets a value to the specified type.
        /// </summary>
        /// <param name="name">The name of the value.</param>
        /// <param name="type">The optional type for the value.</param>
        /// <param name="data">The data for the value.</param>
        private void SetValue(string name, RegValueType type, byte[] data)
        {
            IntPtr dataPtr = IntPtr.Zero;

            try
            {
                dataPtr = Marshal.AllocHGlobal(data.Length);
                Marshal.Copy(data, 0, dataPtr, data.Length);

                Win32Result result = OffregNative.SetValue(_intPtr, name, type, dataPtr, (uint)data.Length);

                if (result != Win32Result.ERROR_SUCCESS)
                {
                    throw new Win32Exception((int)result);
                }
            }
            finally
            {
                if (dataPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(dataPtr);
                }
            }

            RefreshMetadata();
        }
Esempio n. 2
0
        /// <summary>
        /// RegInject: Sets a value to the REG_NONE type. Therefore only its name is required.
        /// </summary>
        /// <param name="name">The name of the value.</param>
        public void SetValueNone(string name)
        {
            IntPtr dataPtr = IntPtr.Zero;

            try
            {
                dataPtr = Marshal.AllocHGlobal(0);
                //Marshal.Copy(data, 0, dataPtr, data.Length);

                Win32Result result = OffregNative.SetValue(
                    _intPtr, name, RegValueType.REG_NONE, dataPtr, (uint)0);

                if (result != Win32Result.ERROR_SUCCESS)
                {
                    throw new Win32Exception((int)result);
                }
            }
            finally
            {
                if (dataPtr != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(dataPtr);
                }
            }

            RefreshMetadata();
        }