RegistryAccessRule Sınıf
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Bir kullanıcı veya grup için izin verilen veya reddedilen erişim hakları kümesini temsil eder. Bu sınıf devralınamaz.
public ref class RegistryAccessRule sealed : System::Security::AccessControl::AccessRule
public sealed class RegistryAccessRule : System.Security.AccessControl.AccessRule
[System.Security.SecurityCritical]
public sealed class RegistryAccessRule : System.Security.AccessControl.AccessRule
type RegistryAccessRule = class
inherit AccessRule
[<System.Security.SecurityCritical>]
type RegistryAccessRule = class
inherit AccessRule
Public NotInheritable Class RegistryAccessRule
Inherits AccessRule
- Devralma
- Öznitelikler
Örnekler
Aşağıdaki kod örneği, devralma ve yayma ile erişim kurallarını gösterir. Örnek bir RegistrySecurity nesne oluşturur, ardından bayrağı olan ContainerInherit iki kural oluşturur ve ekler. İlk kuralda yayma bayrağı olmazken, ikinci kuralda ve NoPropagateInheritbulunurInheritOnly.
Program nesnesindeki RegistrySecurity kuralları görüntüler ve ardından nesnesini kullanarak bir alt anahtar oluşturur. Program bir alt alt anahtar ve bir alt alt anahtar oluşturur ve ardından her alt anahtarın güvenliğini görüntüler. Son olarak, program test anahtarlarını siler.
using System;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Security;
using Microsoft.Win32;
public class Example
{
public static void Main()
{
const string TestKey = "TestKey3927";
RegistryKey cu = Registry.CurrentUser;
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);
// Display the rules in the security object.
ShowSecurity(mSec);
// Create the test key using the security object.
//
RegistryKey rk = cu.CreateSubKey(TestKey,
RegistryKeyPermissionCheck.ReadWriteSubTree, mSec);
// Create a child subkey and a grandchild subkey,
// without security.
RegistryKey rkChild = rk.CreateSubKey("ChildKey",
RegistryKeyPermissionCheck.ReadWriteSubTree);
RegistryKey rkGrandChild =
rkChild.CreateSubKey("GrandChildKey",
RegistryKeyPermissionCheck.ReadWriteSubTree);
Show(rk);
Show(rkChild);
Show(rkGrandChild);
rkGrandChild.Close();
rkChild.Close();
rk.Close();
cu.DeleteSubKeyTree(TestKey);
}
private static void Show(RegistryKey rk)
{
Console.WriteLine(rk.Name);
ShowSecurity(rk.GetAccessControl());
}
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: 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
HKEY_CURRENT_USER\TestKey3927
Current access rules:
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
HKEY_CURRENT_USER\TestKey3927\ChildKey
Current access rules:
User: TestDomain\TestUser
Type: Allow
Rights: SetValue, CreateSubKey, Delete, ReadKey
Inheritance: ContainerInherit
Propagation: None
Inherited? True
User: TestDomain\TestUser
Type: Allow
Rights: ChangePermissions
Inheritance: None
Propagation: None
Inherited? True
HKEY_CURRENT_USER\TestKey3927\ChildKey\GrandChildKey
Current access rules:
User: TestDomain\TestUser
Type: Allow
Rights: SetValue, CreateSubKey, Delete, ReadKey
Inheritance: ContainerInherit
Propagation: None
Inherited? True
*/
Option Explicit
Imports System.Security.AccessControl
Imports System.Security.Principal
Imports System.Security
Imports Microsoft.Win32
Public Class Example
Public Shared Sub Main()
Const TestKey As String = "TestKey3927"
Dim cu As RegistryKey = Registry.CurrentUser
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)
' Display the rules in the security object.
ShowSecurity(mSec)
' Create the test key using the security object.
'
Dim rk As RegistryKey = cu.CreateSubKey(TestKey, _
RegistryKeyPermissionCheck.ReadWriteSubTree, _
mSec)
' Create a child subkey and a grandchild subkey,
' without security.
Dim rkChild As RegistryKey= rk.CreateSubKey("ChildKey", _
RegistryKeyPermissionCheck.ReadWriteSubTree)
Dim rkGrandChild As RegistryKey = _
rkChild.CreateSubKey("GrandChildKey", _
RegistryKeyPermissionCheck.ReadWriteSubTree)
Show(rk)
Show(rkChild)
Show(rkGrandChild)
rkGrandChild.Close()
rkChild.Close()
rk.Close()
cu.DeleteSubKeyTree(TestKey)
End Sub
Private Shared Sub Show(ByVal rk As RegistryKey)
Console.WriteLine(rk.Name)
ShowSecurity(rk.GetAccessControl())
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: 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
'
'HKEY_CURRENT_USER\TestKey3927
'
'Current access rules:
'
' 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
'
'HKEY_CURRENT_USER\TestKey3927\ChildKey
'
'Current access rules:
'
' User: TestDomain\TestUser
' Type: Allow
' Rights: SetValue, CreateSubKey, Delete, ReadKey
' Inheritance: ContainerInherit
' Propagation: None
' Inherited? True
'
' User: TestDomain\TestUser
' Type: Allow
' Rights: ChangePermissions
' Inheritance: None
' Propagation: None
' Inherited? True
'
'HKEY_CURRENT_USER\TestKey3927\ChildKey\GrandChildKey
'
'Current access rules:
'
' User: TestDomain\TestUser
' Type: Allow
' Rights: SetValue, CreateSubKey, Delete, ReadKey
' Inheritance: ContainerInherit
' Propagation: None
' Inherited? True
Açıklamalar
RegistryAccessRule sınıfı, .NET Framework'ün kayıt defteri anahtarlarında Windows erişim denetimi güvenliğini yönetmek için sağladığı bir sınıf kümesidir. Bu sınıflara ve bunların temel alınan Windows erişim denetimi yapılarıyla ilişkisine genel bakış için bkz RegistrySecurity. .
Note
Windows erişim denetimi güvenliği yalnızca kayıt defteri anahtarlarına uygulanabilir. Bir anahtarda depolanan tek tek anahtar/değer çiftlerine uygulanamaz.
Şu anda bir kayıt defteri anahtarına uygulanan kuralların listesini almak için yöntemini kullanarak RegistryKey.GetAccessControl bir RegistrySecurity nesnesi alın ve ardından yöntemini kullanarak GetAccessRules bir nesne koleksiyonu RegistryAccessRule elde edin.
RegistryAccessRule nesneler, temel alınan isteğe bağlı denetim erişim listesindeki (DACL) erişim denetimi girdileriyle bire bir eşlenmez. Bir kayıt defteri anahtarı için tüm erişim kuralları kümesini aldığınızda, küme tüm erişim denetimi girdilerini ifade etmek için şu anda gereken en az sayıda kuralı içerir.
Note
Temel alınan erişim denetimi girdileri siz kuralları uyguladıkçe ve kaldırdıkça değişir. En az sayıda erişim denetimi girdisini korumak için mümkünse kurallardaki bilgiler birleştirilir. Bu nedenle, geçerli kural listesini okuduğunuzda, eklediğiniz tüm kuralların listesi gibi görünmeyebilir.
Bir kullanıcıya veya gruba izin vermek veya reddetmek için erişim hakları belirtmek için nesneleri kullanın RegistryAccessRule . Nesne RegistryAccessRule her zaman izin verilen erişimi veya reddedilen erişimi temsil eder, her ikisini de temsil etmez.
Kayıt defteri anahtarına kural uygulamak için nesnesini almak RegistryKey.GetAccessControl için yöntemini kullanınRegistrySecurity. RegistrySecurity Nesnesini değiştirmek için yöntemini kullanarak kuralı ekleyin ve ardından yöntemini kullanarak RegistryKey.SetAccessControl güvenlik nesnesini yeniden ekleyin.
Important
Bir RegistrySecurity nesnede yaptığınız değişiklikler, değiştirilen güvenlik nesnesini kayıt defteri anahtarına atamak için yöntemini çağırana RegistryKey.SetAccessControl kadar kayıt defteri anahtarının erişim düzeylerini etkilemez.
RegistryAccessRule nesneler sabittir. Bir kayıt defteri anahtarının güvenliği, kuralları eklemek veya kaldırmak için sınıfının yöntemleri RegistrySecurity kullanılarak değiştirilir; bunu yaptığınız gibi, temel erişim denetimi girdileri değiştirilir.
Oluşturucular
| Name | Description |
|---|---|
| RegistryAccessRule(IdentityReference, RegistryRights, AccessControlType) |
Kuralın RegistryAccessRule uygulandığı kullanıcıyı veya grubu, erişim haklarını ve belirtilen erişim haklarına izin verilip verilmeyeceğini belirterek sınıfın yeni bir örneğini başlatır. |
| RegistryAccessRule(IdentityReference, RegistryRights, InheritanceFlags, PropagationFlags, AccessControlType) |
Kuralın RegistryAccessRule uygulandığı kullanıcıyı veya grubu, erişim haklarını, devralma bayraklarını, yayma bayraklarını ve belirtilen erişim haklarına izin verilip verilmeyeceğini belirterek sınıfın yeni bir örneğini başlatır. |
| RegistryAccessRule(String, RegistryRights, AccessControlType) |
Kuralın RegistryAccessRule uygulandığı kullanıcı veya grubun adını, erişim haklarını ve belirtilen erişim haklarına izin verilip verilmeyeceğini belirterek sınıfının yeni bir örneğini başlatır. |
| RegistryAccessRule(String, RegistryRights, InheritanceFlags, PropagationFlags, AccessControlType) |
Kuralın RegistryAccessRule uygulandığı kullanıcı veya grubun adını, erişim haklarını, devralma bayraklarını, yayma bayraklarını ve belirtilen erişim haklarına izin verilip verilmediğini belirterek sınıfın yeni bir örneğini başlatır. |
Özellikler
| Name | Description |
|---|---|
| AccessControlType |
AccessControlType Bu AccessRule nesneyle ilişkili değeri alır. (Devralındığı yer: AccessRule) |
| AccessMask |
Bu kural için erişim maskesini alır. (Devralındığı yer: AuthorizationRule) |
| IdentityReference |
Bu kuralın IdentityReference uygulandığı değeri alır. (Devralındığı yer: AuthorizationRule) |
| InheritanceFlags |
Bu kuralın alt nesneler tarafından nasıl devralındığını belirleyen bayrakların değerini alır. (Devralındığı yer: AuthorizationRule) |
| IsInherited |
Bu kuralın açıkça ayarlandığını veya bir üst kapsayıcı nesnesinden devralındığını belirten bir değer alır. (Devralındığı yer: AuthorizationRule) |
| PropagationFlags |
Bu kuralın devralma işleminin alt nesnelere nasıl yayıldığına karar veren yayma bayraklarının değerini alır. Bu özellik yalnızca sabit listesi değeri InheritanceFlags olmadığında Noneönemlidir. (Devralındığı yer: AuthorizationRule) |
| RegistryRights |
Erişim kuralı tarafından izin verilen veya reddedilen hakları alır. |
Yöntemler
| Name | Description |
|---|---|
| Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler. (Devralındığı yer: Object) |
| GetHashCode() |
Varsayılan karma işlevi işlevi görür. (Devralındığı yer: Object) |
| GetType() |
Geçerli örneğin Type alır. (Devralındığı yer: Object) |
| MemberwiseClone() |
Geçerli Objectbasit bir kopyasını oluşturur. (Devralındığı yer: Object) |
| ToString() |
Geçerli nesneyi temsil eden bir dize döndürür. (Devralındığı yer: Object) |