RegistryRights 列挙体とは? わかりやすく解説

RegistryRights 列挙体

メモ : この列挙体は、.NET Framework version 2.0新しく追加されたものです。

レジストリ オブジェクト適用できるアクセス制御指定します

この列挙体には、メンバ値のビットごとの組み合わせ可能にする FlagsAttribute 属性含まれています。

名前空間: System.Security.AccessControl
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<FlagsAttribute> _
Public Enumeration RegistryRights
Dim instance As RegistryRights
[FlagsAttribute] 
public enum RegistryRights
[FlagsAttribute] 
public enum class RegistryRights
/** @attribute FlagsAttribute() */ 
public enum RegistryRights
FlagsAttribute 
public enum RegistryRights
メンバメンバ
 メンバ説明
ChangePermissionsレジストリ キー関連付けられたアクセス規則監査規則変更する権限。 
CreateLinkシステム使用するために予約されています。 
CreateSubKeyレジストリ キーのサブキーを作成する権限。 
Deleteレジストリ キー削除する権限。 
EnumerateSubKeysレジストリ キーのサブキーをリストする権限。 
ExecuteKeyReadKey と同じです。 
FullControlレジストリ キー対すフル コントロール、およびそのアクセス規則監査規則変更する権限。 
Notifyレジストリ キー変更通知要求する権限。 
QueryValuesレジストリ キー内の名前/値ペア照会する権限。 
ReadKeyレジストリ キー内の名前/値ペア照会変更通知要求、そのサブキーの列挙、そのアクセス規則監査規則読み取りを行う権限。 
ReadPermissionsレジストリ キーアクセス規則監査規則開いてコピーする権限。 
SetValueレジストリ キー内の名前/値ペア作成削除、または設定する権限。 
TakeOwnershipレジストリ キー所有者変更する権限。 
WriteKeyレジストリ キー内の名前/値ペア作成削除、および設定、サブキーの作成または削除変更通知要求、そのサブキーの列挙、そのアクセス規則監査規則読み取りを行う権限。 
解説解説

RegistrySecurity オブジェクト作成する場合に、RegistryRights 列挙体を使用してレジストリ アクセス権指定しますアクセス権レジストリ キー適用するには、まず、RegistryAccessRule オブジェクトRegistrySecurity オブジェクト追加し、RegistryKey.SetAccessControl メソッド使用するか、または Microsoft.Win32.RegistryKey.CreateSubKey メソッド適切なオーバーロード使用してRegistrySecurity オブジェクトキー割り当てます

使用例使用例

RegistryRights 列挙体の使用方法を示すコード例次に示します。このコードでは、テスト キー作成し現在のユーザーに対して ReadKey アクセス権および Delete アクセス権許可し、ChangePermissions および WriteKey 拒否します。これらのアクセス許可基づいてキー操作するための後続試み成功または失敗します

キー削除する前にコード一時停止ます。レジストリ エディタ (Regedit.exe または Regedt32.exe) に切り替えることにより、キーへのアクセスレジストリ エディタ使用した場合でも同じアクセス権適用されることを確認できます

この例は、コマンド ラインから RunAs使用してレジストリ エディタ実行し管理者権限持たないローカル ユーザーとしてサンプル コード実行すると最も効果あります。たとえば、TestUser という名前のローカル ユーザー定義した場合コマンド runas /user:TestUser cmd によってコマンド ウィンドウ開かれ、ここでレジストリ エディタ実行し、このプログラム例実行できます

Imports System
Imports System.Reflection
Imports System.Security
Imports System.Security.AccessControl
Imports Microsoft.Win32

Public Class Example
    Public Shared Sub Main()
        ' Delete the example key if it exists.
        Try
            Registry.CurrentUser.DeleteSubKey("RegistryRightsExample")
            Console.WriteLine("Example key has been deleted.")
        Catch ex As ArgumentException
            ' ArgumentException is thrown if the key does not exist.
 In
            ' this case, there is no reason to display a message.
        Catch ex As Exception
            Console.WriteLine("Unable to delete the example key:
 {0}", ex)
            Return
        End Try

        Dim user As String
 = Environment.UserDomainName & "\" & Environment.UserName

        Dim rs As New RegistrySecurity()

        ' Allow the current user to read and delete the key.
        '
        rs.AddAccessRule(new RegistryAccessRule(user, _
            RegistryRights.ReadKey Or RegistryRights.Delete, _
            InheritanceFlags.None, _
            PropagationFlags.None, _
            AccessControlType.Allow))

        ' Prevent the current user from writing or changing the
        ' permission set of the key. Note that if Delete permission
        ' were not allowed in the previous access rule, denying
        ' WriteKey permission would prevent the user from deleting the
 
        ' key.
        rs.AddAccessRule(new RegistryAccessRule(user, _
            RegistryRights.WriteKey Or RegistryRights.ChangePermissions,
 _
            InheritanceFlags.None, _
            PropagationFlags.None, _
            AccessControlType.Deny))

        ' Create the example key with registry security.
        Dim rk As RegistryKey = Nothing
        Try
            rk = Registry.CurrentUser.CreateSubKey("RegistryRightsExample",
 _
                RegistryKeyPermissionCheck.Default, rs)
            Console.WriteLine(vbCrLf & "Example key created.")
            rk.SetValue("ValueName", "StringValue")
        Catch ex As Exception
            Console.WriteLine(vbCrLf & "Unable to create the
 example key: {0}", ex)
        End Try

        If rk IsNot Nothing Then
 rk.Close()

        rk = Registry.CurrentUser

        Dim rk2 As RegistryKey
        
        ' Open the key with read access.
        rk2 = rk.OpenSubKey("RegistryRightsExample",
 False)
        Console.WriteLine(vbCrLf & "Retrieved value: {0}",
 rk2.GetValue("ValueName"))
        rk2.Close()

        ' Attempt to open the key with write access.
        Try
            rk2 = rk.OpenSubKey("RegistryRightsExample",
 True)
        Catch ex As SecurityException
            Console.WriteLine(vbCrLf & "Unable to write to
 the example key." _
                & " Caught SecurityException: {0}",
 ex.Message)
        End Try
        If rk2 IsNot Nothing Then
 rk2.Close()

        ' Attempt to change permissions for the key.
        Try
            rs = New RegistrySecurity()
            rs.AddAccessRule(new RegistryAccessRule(user, _
                RegistryRights.WriteKey, _
                InheritanceFlags.None, _
                PropagationFlags.None, _
                AccessControlType.Allow))
            rk2 = rk.OpenSubKey("RegistryRightsExample",
 False)
            rk2.SetAccessControl(rs)
            Console.WriteLine(vbCrLf & "Example key permissions
 were changed.")
        Catch ex As UnauthorizedAccessException
            Console.WriteLine(vbCrLf & "Unable to change permissions
 for the example key." _
                & " Caught UnauthorizedAccessException: {0}",
 ex.Message)
        End Try
        If rk2 IsNot Nothing Then
 rk2.Close()

        Console.WriteLine(vbCrLf & "Press Enter to delete
 the example key.")
        Console.ReadLine()

        Try
            rk.DeleteSubKey("RegistryRightsExample")
            Console.WriteLine("Example key was deleted.")
        Catch ex As Exception
            Console.WriteLine("Unable to delete the example key:
 {0}", ex)
        End Try

        rk.Close()
    End Sub
End Class

' This code produces the following output:
'
'Example key created.
'
'Retrieved value: StringValue
'
'Unable to write to the example key. Caught SecurityException: Requested
 registry access is not allowed.
'
'Unable to change permissions for the example key. Caught UnauthorizedAccessException:
 Cannot write to the registry key.
'
'Press Enter to delete the example key.
'
'Example key was deleted.
using System;
using System.Reflection;
using System.Security;
using System.Security.AccessControl;
using Microsoft.Win32;

public class Example
{
    public static void Main()
    {
        // Delete the example key if it exists.
        try
        {
            Registry.CurrentUser.DeleteSubKey("RegistryRightsExample");
            Console.WriteLine("Example key has been deleted.");
        }
        catch (ArgumentException)
        {
            // ArgumentException is thrown if the key does not exist.
 In
            // this case, there is no reason to display a message.
        }
        catch (Exception ex)
        {
            Console.WriteLine("Unable to delete the example key: {0}",
 ex);
            return;
        }

        string user = Environment.UserDomainName + "\\"
 + Environment.UserName;

        RegistrySecurity rs = new RegistrySecurity();

        // Allow the current user to read and delete the key.
        //
        rs.AddAccessRule(new RegistryAccessRule(user, 
            RegistryRights.ReadKey | RegistryRights.Delete, 
            InheritanceFlags.None, 
            PropagationFlags.None, 
            AccessControlType.Allow));

        // Prevent the current user from writing or changing the
        // permission set of the key. Note that if Delete permission
        // were not allowed in the previous access rule, denying
        // WriteKey permission would prevent the user from deleting
 the 
        // key.
        rs.AddAccessRule(new RegistryAccessRule(user, 
            RegistryRights.WriteKey | RegistryRights.ChangePermissions, 
            InheritanceFlags.None, 
            PropagationFlags.None, 
            AccessControlType.Deny));

        // Create the example key with registry security.
        RegistryKey rk = null;
        try
        {
            rk = Registry.CurrentUser.CreateSubKey("RegistryRightsExample",
 
                RegistryKeyPermissionCheck.Default, rs);
            Console.WriteLine("\r\nExample key created.");
            rk.SetValue("ValueName", "StringValue");
        }
        catch (Exception ex)
        {
            Console.WriteLine("\r\nUnable to create the example key: {0}",
 ex);
        }
        if (rk != null) rk.Close();

        rk = Registry.CurrentUser;

        RegistryKey rk2;
        
        // Open the key with read access.
        rk2 = rk.OpenSubKey("RegistryRightsExample", false);
        Console.WriteLine("\r\nRetrieved value: {0}", rk2.GetValue("ValueName"));
        rk2.Close();

        // Attempt to open the key with write access.
        try
        {
            rk2 = rk.OpenSubKey("RegistryRightsExample", true);
        }
        catch (SecurityException ex)
        {
            Console.WriteLine("\nUnable to write to the example key." +
                " Caught SecurityException: {0}", ex.Message);
        }
        if (rk2 != null) rk2.Close();

        // Attempt to change permissions for the key.
        try
        {
            rs = new RegistrySecurity();
            rs.AddAccessRule(new RegistryAccessRule(user, 
                RegistryRights.WriteKey, 
                InheritanceFlags.None, 
                PropagationFlags.None, 
                AccessControlType.Allow));
            rk2 = rk.OpenSubKey("RegistryRightsExample", false);
            rk2.SetAccessControl(rs);
            Console.WriteLine("\r\nExample key permissions were changed.");
        }
        catch (UnauthorizedAccessException ex)
        {
            Console.WriteLine("\nUnable to change permissions for
 the example key." +
                " Caught UnauthorizedAccessException: {0}", ex.Message);
        }
        if (rk2 != null) rk2.Close();

        Console.WriteLine("\r\nPress Enter to delete the example key.");
        Console.ReadLine();

        try
        {
            rk.DeleteSubKey("RegistryRightsExample");
            Console.WriteLine("Example key was deleted.");
        }
        catch(Exception ex)
        {
            Console.WriteLine("Unable to delete the example key: {0}",
 ex);
        }

        rk.Close();
    }
}

/* This code example produces the following output:

Example key created.

Retrieved value: StringValue

Unable to write to the example key. Caught SecurityException: Requested registry
 access is not allowed.

Unable to change permissions for the example key. Caught UnauthorizedAccessException:
 Cannot write to the registry key.

Press Enter to delete the example key.

Example key was deleted.
 */
using namespace System;
using namespace System::Reflection;
using namespace Microsoft::Win32;
using namespace System::Security::AccessControl;
using namespace System::Security;

int main()
{
    // Delete the example key if it exists.
    try
    {
        Registry::CurrentUser->DeleteSubKey("RegistryRightsExample");
        Console::WriteLine("Example key has been deleted.");
    }
    catch (ArgumentException^)
    {
        // ArgumentException is thrown if the key does not exist. In
        // this case, there is no reason to display a message.
    }
    catch (InvalidOperationException^ ex)
    {
        Console::WriteLine(
            "{0}Unable to delete key: it appears to have child subkeys:{0}{1}",
 
            Environment::NewLine, ex);
        return 0;
    }
    catch (SecurityException^ ex)
    {
        Console::WriteLine("{0}You do not have the permissions required "
 +
            "to delete this key:{0}{1}", Environment::NewLine,
 ex);
        return 0;
    }

    String^ user = Environment::UserDomainName + "\\" + Environment::UserName;

    RegistrySecurity^ regSecurity = gcnew RegistrySecurity();

    // Allow the current user to read and delete the key.
    //
    regSecurity->AddAccessRule(gcnew RegistryAccessRule(user,
        RegistryRights::ReadKey | RegistryRights::Delete,
        InheritanceFlags::None,
        PropagationFlags::None,
        AccessControlType::Allow));

    // Prevent the current user from writing or changing the
    // permission set of the key. Note that if Delete permission
    // were not allowed in the previous access rule, denying
    // WriteKey permission would prevent the user from deleting the
    // key.
    regSecurity->AddAccessRule(gcnew RegistryAccessRule(user,
        RegistryRights::WriteKey | RegistryRights::ChangePermissions,
        InheritanceFlags::None,
        PropagationFlags::None,
        AccessControlType::Deny));

    // Create the example key with registry security.
    RegistryKey^ createdKey = nullptr;
    try
    {
        createdKey = Registry::CurrentUser->CreateSubKey(
            "RegistryRightsExample", RegistryKeyPermissionCheck::Default
,
            regSecurity);
        Console::WriteLine("{0}Example key created.", Environment::NewLine);
        createdKey->SetValue("ValueName", "StringValue");
    }
    catch (SecurityException^ ex)
    {
        Console::WriteLine("{0}You do not have the permissions required "
 +
            "to create the example key:{0}{1}", Environment::NewLine, ex);
        return 0;
    }
    if (createdKey != nullptr)
    {
        createdKey->Close();
    }

    RegistryKey^ openedKey;

    // Open the key with read access.
    openedKey = Registry::CurrentUser->OpenSubKey("RegistryRightsExample"
,
        false);
    Console::WriteLine("{0}Retrieved value: {1}",
        Environment::NewLine, openedKey->GetValue("ValueName"));
    openedKey->Close();

    // Attempt to open the key with write access.
    try
    {
        openedKey = Registry::CurrentUser->OpenSubKey("RegistryRightsExample"
,
            true);
    }
    catch (SecurityException^ ex)
    {
        Console::WriteLine("{0}You do not have the permissions required "
 +
            "to write to the example key:{0}{1}", Environment::NewLine,
 ex);
    }
    if (openedKey != nullptr)
    {
        openedKey->Close();
    }

    // Attempt to change permissions for the key.
    try
    {
        regSecurity = gcnew RegistrySecurity();
        regSecurity->AddAccessRule(gcnew RegistryAccessRule(user,
            RegistryRights::WriteKey,
            InheritanceFlags::None,
            PropagationFlags::None,
            AccessControlType::Allow));
        openedKey = Registry::CurrentUser->OpenSubKey("RegistryRightsExample"
,
            false);
        openedKey->SetAccessControl(regSecurity);
        Console::WriteLine("{0}Example key permissions were changed.",
 
            Environment::NewLine);
    }
    catch (UnauthorizedAccessException^ ex)
    {
        Console::WriteLine("{0}You are not authorized to change " +
            "permissions for the example key:{0}{1}",
 Environment::NewLine, ex);
    }
    if (openedKey != nullptr)
    {
        openedKey->Close();
    }

    Console::WriteLine("{0}Press Enter to delete the example key.", 
        Environment::NewLine);
    Console::ReadLine();

    try
    {
        Registry::CurrentUser->DeleteSubKey("RegistryRightsExample");
        Console::WriteLine("Example key was deleted.");
    }
    catch(SecurityException^ ex)
    {
        Console::WriteLine("{0}You do not have the permissions required to "
            + "delete the example key:{0}{1}", Environment::NewLine, ex);
    }
}
import System.*;
import System.Reflection.*;
import System.Security.*;
import System.Security.AccessControl.*;
import Microsoft.Win32.*;

public class Example
{
    public static void main(String[]
 args)
    {
        // Delete the example key if it exists.
        try {
            Registry.CurrentUser.DeleteSubKey("RegistryRightsExample");
            Console.WriteLine("Example key has been deleted.");
        }
        catch (ArgumentException exp) {
            // ArgumentException is thrown if the key does not exist.
 In
            // this case, there is no reason to display a message.
        }
        catch (System.Exception ex) {
            Console.WriteLine("Unable to delete the example key: {0}",
 ex);
            return;
        }

        String user = Environment.get_UserDomainName() + "\\" 
            + Environment.get_UserName();

        RegistrySecurity rs = new RegistrySecurity();
        // Allow the current user to read and delete the key.
        //
        rs.AddAccessRule(new RegistryAccessRule(user, RegistryRights.ReadKey
 
            | RegistryRights.Delete, InheritanceFlags.None, 
            PropagationFlags.None, AccessControlType.Allow));
        // Prevent the current user from writing or changing the
        // permission set of the key. Note that if Delete permission
        // were not allowed in the previous access rule, denying
        // WriteKey permission would prevent the user from deleting
 the 
        // key.
        rs.AddAccessRule(new RegistryAccessRule(user, RegistryRights.WriteKey
 
            | RegistryRights.ChangePermissions, InheritanceFlags.None, 
            PropagationFlags.None, AccessControlType.Deny));
        // Create the example key with registry security.
        RegistryKey rk = null;
        try {
            rk = Registry.CurrentUser.CreateSubKey("RegistryRightsExample",
 
                RegistryKeyPermissionCheck.Default, rs);
            Console.WriteLine("\r\nExample key created.");
            rk.SetValue("ValueName", "StringValue");
        }
        catch (System.Exception ex) {
            Console.WriteLine("\r\nUnable to create the example key: {0}",
 ex);
        }
        if (rk != null) {
            rk.Close();
        }
        rk = Registry.CurrentUser;
        RegistryKey rk2;
        // Open the key with read access.
        rk2 = rk.OpenSubKey("RegistryRightsExample", false);
        Console.WriteLine("\r\nRetrieved value: {0}", rk2.GetValue("ValueName"));
        rk2.Close();
        // Attempt to open the key with write access.
        try {
            rk2 = rk.OpenSubKey("RegistryRightsExample", true);
        }
        catch (System.Security.SecurityException ex) {
            Console.WriteLine("\r\nUnable to write to the example key."
 +
                " Caught SecurityException: {0}", ex.get_Message());
        }
        if (rk2 != null) {
            rk2.Close();
        }
        // Attempt to change permissions for the key.
        try {
            rs = new RegistrySecurity();
            rs.AddAccessRule(new RegistryAccessRule(user, 
                RegistryRights.WriteKey, InheritanceFlags.None, 
                PropagationFlags.None, AccessControlType.Allow));
            rk2 = rk.OpenSubKey("RegistryRightsExample", false);
            rk2.SetAccessControl(rs);
            Console.WriteLine("\r\nExample key permissions were changed.");
        }
        catch (System.UnauthorizedAccessException ex) {
            Console.WriteLine("\r\nUnable to change permissions for
 the example key." +
                " Caught UnauthorizedAccessException: {0}", ex.get_Message());
        }
        if (rk2 != null) {
            rk2.Close();
        }
        Console.WriteLine("\r\nPress Enter to delete the example key.");
        Console.ReadLine();
        try {
            rk.DeleteSubKey("RegistryRightsExample");
            Console.WriteLine("Example key was deleted.");
        }
        catch (System.Exception ex) {
            Console.WriteLine("Unable to delete the example key: {0}",
 ex);
        }
        rk.Close();
    } //main
} //Example

/* This code example produces the following output:

Example key created.

Retrieved value: StringValue

Unable to write to the example key. Caught SecurityException: Requested registry
 access is not allowed.

Unable to change permissions for the example key. Caught UnauthorizedAccessException:
 Cannot write to the registry key.

Press Enter to delete the example key.

Example key was deleted.
 */
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
System.Security.AccessControl 名前空間
RegistryAccessRule クラス
RegistrySecurity
RegistryAuditRule クラス



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「RegistryRights 列挙体」の関連用語

RegistryRights 列挙体のお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



RegistryRights 列挙体のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS