Microsoft.Win32.RegistryKey.InternalOpenSubKeyCore C# (CSharp) Method

InternalOpenSubKeyCore() private method

private InternalOpenSubKeyCore ( string name, RegistryRights rights, bool throwOnPermissionFailure ) : RegistryKey
name string
rights RegistryRights
throwOnPermissionFailure bool
return RegistryKey
        private RegistryKey InternalOpenSubKeyCore(string name, RegistryRights rights, bool throwOnPermissionFailure)
        {
            SafeRegistryHandle result = null;
            int ret = Interop.Advapi32.RegOpenKeyEx(_hkey, name, 0, ((int)rights | (int)_regView), out result);
            if (ret == 0 && !result.IsInvalid)
            {
                RegistryKey key = new RegistryKey(result, IsWritable((int)rights), false, _remoteKey, false, _regView);
                key._keyName = _keyName + "\\" + name;
                return key;
            }

            if (throwOnPermissionFailure)
            {
                if (ret == Interop.Errors.ERROR_ACCESS_DENIED || ret == Interop.Errors.ERROR_BAD_IMPERSONATION_LEVEL)
                {
                    // We need to throw SecurityException here for compatibility reason,
                    // although UnauthorizedAccessException will make more sense.
                    ThrowHelper.ThrowSecurityException(SR.Security_RegistryPermission);
                }
            }

            // Return null if we didn't find the key.
            return null;
        }