RegistrySecurity.RemoveAccessRuleAll(RegistryAccessRule) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정한 규칙과 사용자 및 AccessControlType(허용 또는 거부)이 같은 모든 액세스 제어 규칙을 검색하여 제거합니다.
public:
void RemoveAccessRuleAll(System::Security::AccessControl::RegistryAccessRule ^ rule);
public void RemoveAccessRuleAll (System.Security.AccessControl.RegistryAccessRule rule);
override this.RemoveAccessRuleAll : System.Security.AccessControl.RegistryAccessRule -> unit
Public Sub RemoveAccessRuleAll (rule As RegistryAccessRule)
매개 변수
- rule
- RegistryAccessRule
검색할 사용자 및 RegistryAccessRule을 지정하는 AccessControlType입니다. 이 규칙에서 지정한 모든 권한, 상속 플래그 또는 전파 플래그는 무시됩니다.
예외
rule
이(가) null
인 경우
예제
다음 코드 예제에서는 메서드가 RemoveAccessRuleAll 사용자 및 와 AccessControlType일치하는 모든 규칙을 제거하고 권한 및 플래그를 무시하는 것을 보여 줍니다.
이 예제에서는 개체를 RegistrySecurity 만들고 다른 상속 및 전파 플래그를 사용하여 현재 사용자에 대한 다양한 권한을 허용하고 거부하는 규칙을 추가합니다. 그런 다음 현재 사용자가 소유권을 가져올 수 있는 새 규칙을 만들고 해당 규칙을 메서드에 RemoveAccessRuleAll 전달하여 액세스를 허용하는 두 규칙을 제거합니다.
참고
이 예제에서는 보안 개체를 개체에 RegistryKey 연결하지 않습니다. RegistryKey.GetAccessControl 메서드 및 메서드를 RegistryKey.SetAccessControl 참조하세요.
using System;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Security;
using Microsoft.Win32;
public class Example
{
public static void Main()
{
string user = Environment.UserDomainName + "\\"
+ Environment.UserName;
// Create a security object that grants no access.
RegistrySecurity mSec = new RegistrySecurity();
// Add a rule that grants the current user the right
// to read and enumerate the name/value pairs in a key,
// to read its access and audit rules, to enumerate
// its subkeys, to create subkeys, and to delete the key.
// The rule is inherited by all contained subkeys.
//
RegistryAccessRule rule = new RegistryAccessRule(user,
RegistryRights.ReadKey | RegistryRights.WriteKey
| RegistryRights.Delete,
InheritanceFlags.ContainerInherit,
PropagationFlags.None,
AccessControlType.Allow);
mSec.AddAccessRule(rule);
// Add a rule that allows the current user the right
// right to set the name/value pairs in a key.
// This rule is inherited by contained subkeys, but
// propagation flags limit it to immediate child
// subkeys.
rule = new RegistryAccessRule(user,
RegistryRights.ChangePermissions,
InheritanceFlags.ContainerInherit,
PropagationFlags.InheritOnly | PropagationFlags.NoPropagateInherit,
AccessControlType.Allow);
mSec.AddAccessRule(rule);
// Add a rule that denies the current user the right
// to set the name/value pairs in a key. This rule
// has no inheritance or propagation flags, so it
// affects only the key itself.
rule = new RegistryAccessRule(user,
RegistryRights.SetValue,
AccessControlType.Deny);
mSec.AddAccessRule(rule);
// Display the rules in the security object.
ShowSecurity(mSec);
// Create a rule that allows the current user the
// right to change the ownership of the key, with
// no inheritance or propagation flags. The rights
// and flags are ignored by RemoveAccessRuleAll,
// and all rules that allow access for the current
// user are removed.
rule = new RegistryAccessRule(user,
RegistryRights.TakeOwnership,
AccessControlType.Allow);
mSec.RemoveAccessRuleAll(rule);
// Show that all rules that allow access have been
// removed.
ShowSecurity(mSec);
}
private static void ShowSecurity(RegistrySecurity security)
{
Console.WriteLine("\r\nCurrent access rules:\r\n");
foreach( RegistryAccessRule ar in
security.GetAccessRules(true, true, typeof(NTAccount)) )
{
Console.WriteLine(" User: {0}", ar.IdentityReference);
Console.WriteLine(" Type: {0}", ar.AccessControlType);
Console.WriteLine(" Rights: {0}", ar.RegistryRights);
Console.WriteLine(" Inheritance: {0}", ar.InheritanceFlags);
Console.WriteLine(" Propagation: {0}", ar.PropagationFlags);
Console.WriteLine(" Inherited? {0}", ar.IsInherited);
Console.WriteLine();
}
}
}
/* This code example produces output similar to following:
Current access rules:
User: TestDomain\TestUser
Type: Deny
Rights: SetValue
Inheritance: None
Propagation: None
Inherited? False
User: TestDomain\TestUser
Type: Allow
Rights: SetValue, CreateSubKey, Delete, ReadKey
Inheritance: ContainerInherit
Propagation: None
Inherited? False
User: TestDomain\TestUser
Type: Allow
Rights: ChangePermissions
Inheritance: ContainerInherit
Propagation: NoPropagateInherit, InheritOnly
Inherited? False
Current access rules:
User: TestDomain\TestUser
Type: Deny
Rights: SetValue
Inheritance: None
Propagation: None
Inherited? False
*/
Option Explicit
Imports System.Security.AccessControl
Imports System.Security.Principal
Imports System.Security
Imports Microsoft.Win32
Public Class Example
Public Shared Sub Main()
Dim user As String = Environment.UserDomainName _
& "\" & Environment.UserName
' Create a security object that grants no access.
Dim mSec As New RegistrySecurity()
' Add a rule that grants the current user the right
' to read and enumerate the name/value pairs in a key,
' to read its access and audit rules, to enumerate
' its subkeys, to create subkeys, and to delete the key.
' The rule is inherited by all contained subkeys.
'
Dim rule As New RegistryAccessRule(user, _
RegistryRights.ReadKey Or RegistryRights.WriteKey _
Or RegistryRights.Delete, _
InheritanceFlags.ContainerInherit, _
PropagationFlags.None, _
AccessControlType.Allow)
mSec.AddAccessRule(rule)
' Add a rule that allows the current user the right
' right to set the name/value pairs in a key.
' This rule is inherited by contained subkeys, but
' propagation flags limit it to immediate child
' subkeys.
rule = New RegistryAccessRule(user, _
RegistryRights.ChangePermissions, _
InheritanceFlags.ContainerInherit, _
PropagationFlags.InheritOnly Or PropagationFlags.NoPropagateInherit, _
AccessControlType.Allow)
mSec.AddAccessRule(rule)
' Add a rule that denies the current user the right
' to set the name/value pairs in a key. This rule
' has no inheritance or propagation flags, so it
' affects only the key itself.
rule = New RegistryAccessRule(user, _
RegistryRights.SetValue, _
AccessControlType.Deny)
mSec.AddAccessRule(rule)
' Display the rules in the security object.
ShowSecurity(mSec)
' Create a rule that allows the current user the
' right to change the ownership of the key, with
' no inheritance or propagation flags. The rights
' and flags are ignored by RemoveAccessRuleAll,
' and all rules that allow access for the current
' user are removed.
rule = New RegistryAccessRule(user, _
RegistryRights.TakeOwnership, _
AccessControlType.Allow)
mSec.RemoveAccessRuleAll(rule)
' Show that all rules that allow access have been
' removed.
ShowSecurity(mSec)
End Sub
Private Shared Sub ShowSecurity(ByVal security As RegistrySecurity)
Console.WriteLine(vbCrLf & "Current access rules:" & vbCrLf)
For Each ar As RegistryAccessRule In _
security.GetAccessRules(True, True, GetType(NTAccount))
Console.WriteLine(" User: {0}", ar.IdentityReference)
Console.WriteLine(" Type: {0}", ar.AccessControlType)
Console.WriteLine(" Rights: {0}", ar.RegistryRights)
Console.WriteLine(" Inheritance: {0}", ar.InheritanceFlags)
Console.WriteLine(" Propagation: {0}", ar.PropagationFlags)
Console.WriteLine(" Inherited? {0}", ar.IsInherited)
Console.WriteLine()
Next
End Sub
End Class
'This code example produces output similar to following:
'
'Current access rules:
'
' User: TestDomain\TestUser
' Type: Deny
' Rights: SetValue
' Inheritance: None
' Propagation: None
' Inherited? False
'
' User: TestDomain\TestUser
' Type: Allow
' Rights: SetValue, CreateSubKey, Delete, ReadKey
' Inheritance: ContainerInherit
' Propagation: None
' Inherited? False
'
' User: TestDomain\TestUser
' Type: Allow
' Rights: ChangePermissions
' Inheritance: ContainerInherit
' Propagation: NoPropagateInherit, InheritOnly
' Inherited? False
'
'
'Current access rules:
'
' User: TestDomain\TestUser
' Type: Deny
' Rights: SetValue
' Inheritance: None
' Propagation: None
' Inherited? False
'
설명
현재 RegistrySecurity 는 사용자와 AccessControlType 값 rule
이 같은 규칙을 검색합니다. 이 검색을 수행할 때 에 지정된 rule
모든 권한, 상속 플래그 또는 전파 플래그는 무시됩니다. 일치하는 규칙을 찾을 수 없으면 아무 작업도 수행되지 않습니다.
예를 들어 사용자에게 상속 및 전파 플래그가 다른 다양한 권한을 허용하는 여러 규칙이 있는 경우 임의의 권한 및 플래그를 사용하여 사용자 및 AccessControlType.Allow를 지정하는 개체를 만들고 RegistryAccessRule 해당 규칙을 메서드에 RemoveAccessRuleAll 전달하여 이러한 모든 규칙을 제거할 수 있습니다.
적용 대상
.NET