Example #1
0
        /// <summary>
        /// Creates the specified registry key. If the key already exists, the function opens it.
        /// </summary>
        /// <param name="hKey">A handle to an open registry key.</param>
        /// <param name="lpSubKey">
        /// The name of a subkey that this function opens or creates. The subkey specified must be
        /// a subkey of the key identified by the hKey parameter. The parameter cannot be NULL.
        /// </param>
        /// <param name="reserved">This parameter is reserved and must be zero.</param>
        /// <param name="lpClass">Ignored.</param>
        /// <param name="dwOptions">Ignored.</param>
        /// <param name="samDesired">Ignored.</param>
        /// <param name="lpSecurityAttributes">Ignored.</param>
        /// <param name="phkResult">
        /// A pointer to a variable that receives a handle to the opened or created key.
        /// If the key is not one of the predefined registry keys, call the RegCloseKey function
        /// after you have finished using the handle.
        /// </param>
        /// <param name="lpdwDisposition">
        /// A pointer to a variable that receives 0x00000001L if the key is created,
        /// or 0x00000002L if the key is opened.
        /// </param>
        /// <returns></returns>
        public NativeResultCode CreateKeyEx(UIntPtr hKey, string lpSubKey, int reserved, string lpClass, RegOption dwOptions,
                                            RegAccessRights samDesired, ref int lpSecurityAttributes, ref UIntPtr phkResult, ref RegCreationDisposition lpdwDisposition)
        {
            if (lpSubKey == null)
            {
                SafeWrite(RegCreationDisposition.NoKeyCreated, ref lpdwDisposition);
                return(NativeResultCode.RegBadKey);
            }
            uint handle;

            if (!TryParse(hKey, out handle))
            {
                SafeWrite(RegCreationDisposition.NoKeyCreated, ref lpdwDisposition);
                return(NativeResultCode.InvalidHandle);
            }
            using (EngineCore.Engine.GetEngineProcessingSpace())
            {
                uint phkResultHandle;
                RegCreationDisposition creationDisposition;
                var resultCode = _registry.CreateKey(handle, lpSubKey, out phkResultHandle, out creationDisposition);
                EngineCore.Log.Debug("CreateKey(HKey={0} NewSubKey={1}) => {2}",
                                     hKey, lpSubKey, resultCode == NativeResultCode.Success
                                              ? creationDisposition + " HKey=" + phkResultHandle
                                              : resultCode.ToString());
                SafeWrite(creationDisposition, ref lpdwDisposition);
                phkResult = new UIntPtr(phkResultHandle);
                return(resultCode);
            }
        }
 /// <summary>
 /// Open key will open a key  from the VREG, or create it if not available.
 /// </summary>
 /// <param name="hKey"></param>
 /// <param name="subKey"></param>
 /// <param name="options"></param>
 /// <param name="sam"></param>
 /// <param name="phkResult"></param>
 /// <returns></returns>
 public NativeResultCode OpenKey(UIntPtr hKey, string subKey, RegOption options, RegAccessRights sam, out UIntPtr phkResult)
 {
   if (subKey == null)
   {
     phkResult = hKey;
     return NativeResultCode.Success;
   }
   uint handle;
   if (!TryParse(hKey, out handle))
   {
     phkResult = UIntPtr.Zero;
     return NativeResultCode.InvalidHandle;
   }
   using (EngineCore.Engine.GetEngineProcessingSpace())
   {
     uint hSubKey;
     var resultCode = _registry.OpenKey(handle, subKey, out hSubKey);
     EngineCore.Log.Debug(@"OpenKey({0}\\{1}) => {2}", hKey, subKey,
                         resultCode == NativeResultCode.Success ? hSubKey.ToString() : resultCode.ToString());
     phkResult = new UIntPtr(hSubKey);
     return resultCode;
   }
 }
Example #3
0
        /// <summary>
        /// Open key will open a key  from the VREG, or create it if not available.
        /// </summary>
        /// <param name="hKey"></param>
        /// <param name="subKey"></param>
        /// <param name="options"></param>
        /// <param name="sam"></param>
        /// <param name="phkResult"></param>
        /// <returns></returns>
        public NativeResultCode OpenKey(UIntPtr hKey, string subKey, RegOption options, RegAccessRights sam, out UIntPtr phkResult)
        {
            if (subKey == null)
            {
                phkResult = hKey;
                return(NativeResultCode.Success);
            }
            uint handle;

            if (!TryParse(hKey, out handle))
            {
                phkResult = UIntPtr.Zero;
                return(NativeResultCode.InvalidHandle);
            }
            using (EngineCore.Engine.GetEngineProcessingSpace())
            {
                uint hSubKey;
                var  resultCode = _registry.OpenKey(handle, subKey, out hSubKey);
                EngineCore.Log.Debug(@"OpenKey({0}\\{1}) => {2}", hKey, subKey,
                                     resultCode == NativeResultCode.Success ? hSubKey.ToString() : resultCode.ToString());
                phkResult = new UIntPtr(hSubKey);
                return(resultCode);
            }
        }
 /// <summary>
 /// Creates the specified registry key. If the key already exists, the function opens it.
 /// </summary>
 /// <param name="hKey">A handle to an open registry key.</param>
 /// <param name="lpSubKey">
 /// The name of a subkey that this function opens or creates. The subkey specified must be
 /// a subkey of the key identified by the hKey parameter. The parameter cannot be NULL.
 /// </param>
 /// <param name="reserved">This parameter is reserved and must be zero.</param>
 /// <param name="lpClass">Ignored.</param>
 /// <param name="dwOptions">Ignored.</param>
 /// <param name="samDesired">Ignored.</param>
 /// <param name="lpSecurityAttributes">Ignored.</param>
 /// <param name="phkResult">
 /// A pointer to a variable that receives a handle to the opened or created key.
 /// If the key is not one of the predefined registry keys, call the RegCloseKey function
 /// after you have finished using the handle.
 /// </param>
 /// <param name="lpdwDisposition">
 /// A pointer to a variable that receives 0x00000001L if the key is created,
 /// or 0x00000002L if the key is opened.
 /// </param>
 /// <returns></returns>
 public NativeResultCode CreateKeyEx(UIntPtr hKey, string lpSubKey, int reserved, string lpClass, RegOption dwOptions,
   RegAccessRights samDesired, ref int lpSecurityAttributes, ref UIntPtr phkResult, ref RegCreationDisposition lpdwDisposition)
 {
   if (lpSubKey == null)
   {
     SafeWrite(RegCreationDisposition.NoKeyCreated, ref lpdwDisposition);
     return NativeResultCode.RegBadKey;
   }
   uint handle;
   if (!TryParse(hKey, out handle))
   {
     SafeWrite(RegCreationDisposition.NoKeyCreated, ref lpdwDisposition);
     return NativeResultCode.InvalidHandle;
   }
   using (EngineCore.Engine.GetEngineProcessingSpace())
   {
     uint phkResultHandle;
     RegCreationDisposition creationDisposition;
     var resultCode = _registry.CreateKey(handle, lpSubKey, out phkResultHandle, out creationDisposition);
     EngineCore.Log.Debug("CreateKey(HKey={0} NewSubKey={1}) => {2}",
                         hKey, lpSubKey, resultCode == NativeResultCode.Success
                                           ? creationDisposition + " HKey=" + phkResultHandle
                                           : resultCode.ToString());
     SafeWrite(creationDisposition, ref lpdwDisposition);
     phkResult = new UIntPtr(phkResultHandle);
     return resultCode;
   }
 }