Example #1
0
        public static KeyHandle Create(
            KeyAccess access,
            string name,
            ObjectFlags objectFlags,
            KeyHandle rootDirectory,
            RegOptions createOptions,
            out KeyCreationDisposition creationDisposition
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(name, objectFlags, rootDirectory);
            IntPtr           handle;

            try
            {
                if ((status = Win32.NtCreateKey(
                         out handle,
                         access,
                         ref oa,
                         0,
                         IntPtr.Zero,
                         createOptions,
                         out creationDisposition
                         )) >= NtStatus.Error)
                {
                    Win32.ThrowLastError(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new KeyHandle(handle, true));
        }
Example #2
0
 public static KeyHandle Create(
     KeyAccess access,
     string name,
     RegOptions createOptions
     )
 {
     return(Create(access, name, 0, null, createOptions));
 }
Example #3
0
 private static extern int RegCreateKeyEx(
     uint hKey,
     string lpSubKey,
     int lpReserved,
     string lpClass,
     RegOptions dwOptions,
     int samDesired,
     IntPtr lpSecurityAttributes,
     ref uint phkResult,
     ref KeyDisposition lpdwDisposition);
Example #4
0
        /// <summary>
        ///  Creates a new subkey or opens an existing subkey.
        ///  The string subKey is not case-sensitive.
        ///  <para><b>New in v1.3</b></para>
        /// </summary>
        /// <param name="subkey">Name or path of subkey to create or open.</param>
        /// <param name="createVolatile">If true creates a volatile key (Requires Windows CE 5.0).</param>
        /// <returns>Returns the subkey, or null if the operation failed.</returns>
        /// <exception cref="System.ArgumentNullException">The specified subkey is null.</exception>
        /// <exception cref="System.ArgumentException">The length of the specified subkey is longer than the maximum length allowed (255 characters).</exception>
        /// <exception cref="System.ObjectDisposedException">The RegistryKey on which this method is being invoked is closed (closed keys cannot be accessed).</exception>
        public RegistryKey CreateSubKey(string subkey, bool createVolatile)
        {
            //check handle is valid
            if (CheckHKey())
            {
                //check subkey is not null
                if (subkey != null)
                {
                    //check subkey length
                    if (subkey.Length < 256)
                    {
                        //handle to new registry key
                        uint newhandle = 0;

                        //key disposition - did this create a new key or open an existing key
                        KeyDisposition kdisp = 0;

                        //options
                        RegOptions options = 0;
                        if (createVolatile)
                        {
                            options = RegOptions.Volatile;
                        }

                        //create new key
                        int result = RegCreateKeyEx(m_handle, subkey, 0, null, options, 0, IntPtr.Zero, ref newhandle, ref kdisp);

                        if (result == 0)
                        {
                            //success return the new key
                            return(new RegistryKey(newhandle, m_name + "\\" + subkey, true, false));
                        }
                        else
                        {
                            throw new ExternalException("An error occured creating the registry key.");
                        }
                    }
                    else
                    {
                        //name is more than 255 chars
                        throw new ArgumentException("The length of the specified subkey is longer than the maximum length allowed (255 characters).");
                    }
                }
                else
                {
                    throw new ArgumentNullException("The specified subkey is null.");
                }
            }
            else
            {
                //registry key is closed
                throw new ObjectDisposedException("The RegistryKey on which this method is being invoked is closed (closed keys cannot be accessed).");
            }
        }
Example #5
0
        public static KeyHandle Create(
            KeyAccess access,
            string name,
            ObjectFlags objectFlags,
            KeyHandle rootDirectory,
            RegOptions createOptions
            )
        {
            KeyCreationDisposition creationDisposition;

            return(Create(access, name, objectFlags, rootDirectory, createOptions, out creationDisposition));
        }
Example #6
0
		private static extern int RegCreateKeyEx(
			uint hKey,
			string lpSubKey,
			int lpReserved,
			string lpClass,
			RegOptions dwOptions,
			int samDesired,
			IntPtr lpSecurityAttributes,
			ref uint phkResult, 
			ref KeyDisposition lpdwDisposition); 
Example #7
0
 public static extern Win32Error RegCreateKeyEx(
     IntPtr hKey,
     [MarshalAs(UnmanagedType.LPWStr)] string lpSubKey,
     uint Reserved,
     [MarshalAs(UnmanagedType.LPWStr)] string lpClass,
     RegOptions dwOptions,
     RegSecurityAndAccessMask samDesired,
     IntPtr lpSecurityAttributes,
     out IntPtr phkResult,
     out RegDisposition lpdwDisposition);