FileSystemAccessRule コンストラクター

定義

FileSystemAccessRule クラスの新しいインスタンスを初期化します。

オーバーロード

FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType)

ユーザー アカウントへの参照、アクセス規則に関連付けられた操作の種類を指定する値、およびその操作を許可するか拒否するかを指定する値を使用して、FileSystemAccessRule クラスの新しいインスタンスを初期化します。

FileSystemAccessRule(String, FileSystemRights, AccessControlType)

ユーザー アカウントの名前、アクセス規則に関連付けられた操作の種類を指定する値、およびその操作を許可するか拒否するかを示す値を使用して、FileSystemAccessRule クラスの新しいインスタンスを初期化します。

FileSystemAccessRule(IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)

ユーザー アカウントへの参照、アクセス規則に関連付けられた操作の種類を指定する値、権限の継承方法を決定する値、権限の反映方法を決定する値、および操作を許可するか拒否するかを指定する値を使用して、FileSystemAccessRule クラスの新しいインスタンスを初期化します。

FileSystemAccessRule(String, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)

ユーザー アカウント名、アクセス規則に関連付けられた操作の種類を指定する値、権限の継承方法を決定する値、権限の反映方法を決定する値、および操作を許可するか拒否するかを指定する値を使用して、FileSystemAccessRule クラスの新しいインスタンスを初期化します。

FileSystemAccessRule(IdentityReference, FileSystemRights, AccessControlType)

ユーザー アカウントへの参照、アクセス規則に関連付けられた操作の種類を指定する値、およびその操作を許可するか拒否するかを指定する値を使用して、FileSystemAccessRule クラスの新しいインスタンスを初期化します。

public:
 FileSystemAccessRule(System::Security::Principal::IdentityReference ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::AccessControlType type);
public FileSystemAccessRule (System.Security.Principal.IdentityReference identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.FileSystemAccessRule : System.Security.Principal.IdentityReference * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.FileSystemAccessRule
Public Sub New (identity As IdentityReference, fileSystemRights As FileSystemRights, type As AccessControlType)

パラメーター

identity
IdentityReference

ユーザー アカウントへの参照をカプセル化する IdentityReference オブジェクト。

fileSystemRights
FileSystemRights

アクセス規則に関連付けられた操作の種類を指定する FileSystemRights 値のいずれか。

type
AccessControlType

操作を許可するか拒否するかを指定する AccessControlType 値のいずれか。

例外

identity パラメーターが IdentityReference オブジェクトではありません。

identity パラメーターが null です。

type パラメーターに誤った列挙体が渡されました。

注釈

このコンストラクターを使用して、またはDirectorySecurityクラスを使用して永続化できるアクセス制御規則をFileSecurity作成します。 アクセス制御規則では、Microsoft Windows を実行しているコンピューターで許可または禁止されるアクションを決定するユーザー アカウント権限を定義します。

適用対象

FileSystemAccessRule(String, FileSystemRights, AccessControlType)

ユーザー アカウントの名前、アクセス規則に関連付けられた操作の種類を指定する値、およびその操作を許可するか拒否するかを示す値を使用して、FileSystemAccessRule クラスの新しいインスタンスを初期化します。

public:
 FileSystemAccessRule(System::String ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::AccessControlType type);
public FileSystemAccessRule (string identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.FileSystemAccessRule : string * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.FileSystemAccessRule
Public Sub New (identity As String, fileSystemRights As FileSystemRights, type As AccessControlType)

パラメーター

identity
String

ユーザー アカウント名。

fileSystemRights
FileSystemRights

アクセス規則に関連付けられた操作の種類を指定する FileSystemRights 値のいずれか。

type
AccessControlType

操作を許可するか拒否するかを指定する AccessControlType 値のいずれか。

例外

identity パラメーターが null です。

type パラメーターに誤った列挙体が渡されました。

次のコード例では、クラスを FileSecurity 使用して、ファイルにアクセス制御エントリ (ACE) を追加して削除します。 この例を実行するには、有効なユーザーまたはグループ アカウントを指定する必要があります。

using namespace System;
using namespace System::IO;
using namespace System::Security::AccessControl;

// Adds an ACL entry on the specified file for the specified account.

void AddFileSecurity(String^ fileName, String^ account, 
                        FileSystemRights rights, AccessControlType controlType)
{
    // Get a FileSecurity object that represents the 
    // current security settings.
    FileSecurity^ fSecurity = File::GetAccessControl(fileName);

    // Add the FileSystemAccessRule to the security settings. 
    fSecurity->AddAccessRule(gcnew FileSystemAccessRule
                                   (account,rights, controlType));

    // Set the new access settings.
    File::SetAccessControl(fileName, fSecurity);
}

// Removes an ACL entry on the specified file for the specified account.

void RemoveFileSecurity(String^ fileName, String^ account, 
                        FileSystemRights rights, AccessControlType controlType)
{

    // Get a FileSecurity object that represents the 
    // current security settings.
    FileSecurity^ fSecurity = File::GetAccessControl(fileName);

    // Remove the FileSystemAccessRule from the security settings. 
    fSecurity->RemoveAccessRule(gcnew FileSystemAccessRule
                                      (account,rights, controlType));

    // Set the new access settings.
    File::SetAccessControl(fileName, fSecurity);
}

int main()
{
    try
    {
        String^ fileName = "test.xml";

        Console::WriteLine("Adding access control entry for " + fileName);

        // Add the access control entry to the file.
        AddFileSecurity(fileName, "MYDOMAIN\\MyAccount", 
            FileSystemRights::ReadData, AccessControlType::Allow);

        Console::WriteLine("Removing access control entry from " + fileName);

        // Remove the access control entry from the file.
        RemoveFileSecurity(fileName, "MYDOMAIN\\MyAccount", 
            FileSystemRights::ReadData, AccessControlType::Allow);

        Console::WriteLine("Done.");
    }
    catch (Exception^ ex)
    {
        Console::WriteLine(ex->Message);
    }
}
using System;
using System.IO;
using System.Security.AccessControl;

namespace FileSystemExample
{
    class FileExample
    {
        public static void Main()
        {
            try
            {
                string fileName = "test.xml";

                Console.WriteLine("Adding access control entry for "
                    + fileName);

                // Add the access control entry to the file.
                AddFileSecurity(fileName, @"DomainName\AccountName",
                    FileSystemRights.ReadData, AccessControlType.Allow);

                Console.WriteLine("Removing access control entry from "
                    + fileName);

                // Remove the access control entry from the file.
                RemoveFileSecurity(fileName, @"DomainName\AccountName",
                    FileSystemRights.ReadData, AccessControlType.Allow);

                Console.WriteLine("Done.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }

        // Adds an ACL entry on the specified file for the specified account.
        public static void AddFileSecurity(string fileName, string account,
            FileSystemRights rights, AccessControlType controlType)
        {

            // Get a FileSecurity object that represents the
            // current security settings.
            FileSecurity fSecurity = File.GetAccessControl(fileName);

            // Add the FileSystemAccessRule to the security settings.
            fSecurity.AddAccessRule(new FileSystemAccessRule(account,
                rights, controlType));

            // Set the new access settings.
            File.SetAccessControl(fileName, fSecurity);
        }

        // Removes an ACL entry on the specified file for the specified account.
        public static void RemoveFileSecurity(string fileName, string account,
            FileSystemRights rights, AccessControlType controlType)
        {

            // Get a FileSecurity object that represents the
            // current security settings.
            FileSecurity fSecurity = File.GetAccessControl(fileName);

            // Remove the FileSystemAccessRule from the security settings.
            fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,
                rights, controlType));

            // Set the new access settings.
            File.SetAccessControl(fileName, fSecurity);
        }
    }
}
Imports System.IO
Imports System.Security.AccessControl



Module FileExample

    Sub Main()
        Try
            Dim fileName As String = "test.xml"

            Console.WriteLine("Adding access control entry for " & fileName)

            ' Add the access control entry to the file.
            AddFileSecurity(fileName, "DomainName\AccountName", _
                FileSystemRights.ReadData, AccessControlType.Allow)

            Console.WriteLine("Removing access control entry from " & fileName)

            ' Remove the access control entry from the file.
            RemoveFileSecurity(fileName, "DomainName\AccountName", _
                FileSystemRights.ReadData, AccessControlType.Allow)

            Console.WriteLine("Done.")
        Catch e As Exception
            Console.WriteLine(e)
        End Try

    End Sub


    ' Adds an ACL entry on the specified file for the specified account.
    Sub AddFileSecurity(ByVal fileName As String, ByVal account As String, _
        ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)
  
        ' Get a FileSecurity object that represents the 
        ' current security settings.
        Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)

        ' Add the FileSystemAccessRule to the security settings. 
        Dim accessRule As FileSystemAccessRule = _
            New FileSystemAccessRule(account, rights, controlType)

        fSecurity.AddAccessRule(accessRule)

        ' Set the new access settings.
        File.SetAccessControl(fileName, fSecurity)

    End Sub


    ' Removes an ACL entry on the specified file for the specified account.
    Sub RemoveFileSecurity(ByVal fileName As String, ByVal account As String, _
        ByVal rights As FileSystemRights, ByVal controlType As AccessControlType)

        ' Get a FileSecurity object that represents the 
        ' current security settings.
        Dim fSecurity As FileSecurity = File.GetAccessControl(fileName)

        ' Remove the FileSystemAccessRule from the security settings. 
        fSecurity.RemoveAccessRule(New FileSystemAccessRule(account, _
            rights, controlType))

        ' Set the new access settings.
        File.SetAccessControl(fileName, fSecurity)

    End Sub
End Module

注釈

このコンストラクターを使用して、またはDirectorySecurityクラスを使用して永続化できるアクセス制御規則をFileSecurity作成します。 アクセス制御規則では、Microsoft Windows を実行しているコンピューターで許可または禁止されるアクションを決定するユーザー アカウント権限を定義します。

このパラメーターは identity 、現在のコンピューターまたはドメイン上の有効なアカウントを識別する必要があります。 この文字列は、有効なドメインまたはコンピューター名の名前でaccountDOMAINドメインまたはコンピューターDOMAIN\account上の有効なユーザー アカウントの名前を表す次の形式になります。

適用対象

FileSystemAccessRule(IdentityReference, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)

ユーザー アカウントへの参照、アクセス規則に関連付けられた操作の種類を指定する値、権限の継承方法を決定する値、権限の反映方法を決定する値、および操作を許可するか拒否するかを指定する値を使用して、FileSystemAccessRule クラスの新しいインスタンスを初期化します。

public:
 FileSystemAccessRule(System::Security::Principal::IdentityReference ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::InheritanceFlags inheritanceFlags, System::Security::AccessControl::PropagationFlags propagationFlags, System::Security::AccessControl::AccessControlType type);
public FileSystemAccessRule (System.Security.Principal.IdentityReference identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.InheritanceFlags inheritanceFlags, System.Security.AccessControl.PropagationFlags propagationFlags, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.FileSystemAccessRule : System.Security.Principal.IdentityReference * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.InheritanceFlags * System.Security.AccessControl.PropagationFlags * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.FileSystemAccessRule
Public Sub New (identity As IdentityReference, fileSystemRights As FileSystemRights, inheritanceFlags As InheritanceFlags, propagationFlags As PropagationFlags, type As AccessControlType)

パラメーター

identity
IdentityReference

ユーザー アカウントへの参照をカプセル化する IdentityReference オブジェクト。

fileSystemRights
FileSystemRights

アクセス規則に関連付けられた操作の種類を指定する FileSystemRights 値のいずれか。

inheritanceFlags
InheritanceFlags

子オブジェクトにアクセス マスクを反映する方法を指定する InheritanceFlags 値のいずれか。

propagationFlags
PropagationFlags

子オブジェクトにアクセス制御エントリ (ACE) を反映する方法を指定する PropagationFlags 値のいずれか。

type
AccessControlType

操作を許可するか拒否するかを指定する AccessControlType 値のいずれか。

例外

identity パラメーターが IdentityReference オブジェクトではありません。

identity パラメーターが null です。

type パラメーターに誤った列挙体が渡されました。

  • または - inheritanceFlags パラメーターに誤った列挙体が渡されました。

  • または - propagationFlags パラメーターに誤った列挙体が渡されました。

注釈

このコンストラクターを使用して、またはDirectorySecurityクラスを使用して永続化できるアクセス制御規則をFileSecurity作成します。 アクセス制御規則では、Microsoft Windows を実行しているコンピューターで許可または禁止されるアクションを決定するユーザー アカウント権限を定義します。

適用対象

FileSystemAccessRule(String, FileSystemRights, InheritanceFlags, PropagationFlags, AccessControlType)

ユーザー アカウント名、アクセス規則に関連付けられた操作の種類を指定する値、権限の継承方法を決定する値、権限の反映方法を決定する値、および操作を許可するか拒否するかを指定する値を使用して、FileSystemAccessRule クラスの新しいインスタンスを初期化します。

public:
 FileSystemAccessRule(System::String ^ identity, System::Security::AccessControl::FileSystemRights fileSystemRights, System::Security::AccessControl::InheritanceFlags inheritanceFlags, System::Security::AccessControl::PropagationFlags propagationFlags, System::Security::AccessControl::AccessControlType type);
public FileSystemAccessRule (string identity, System.Security.AccessControl.FileSystemRights fileSystemRights, System.Security.AccessControl.InheritanceFlags inheritanceFlags, System.Security.AccessControl.PropagationFlags propagationFlags, System.Security.AccessControl.AccessControlType type);
new System.Security.AccessControl.FileSystemAccessRule : string * System.Security.AccessControl.FileSystemRights * System.Security.AccessControl.InheritanceFlags * System.Security.AccessControl.PropagationFlags * System.Security.AccessControl.AccessControlType -> System.Security.AccessControl.FileSystemAccessRule
Public Sub New (identity As String, fileSystemRights As FileSystemRights, inheritanceFlags As InheritanceFlags, propagationFlags As PropagationFlags, type As AccessControlType)

パラメーター

identity
String

ユーザー アカウント名。

fileSystemRights
FileSystemRights

アクセス規則に関連付けられた操作の種類を指定する FileSystemRights 値のいずれか。

inheritanceFlags
InheritanceFlags

子オブジェクトにアクセス マスクを反映する方法を指定する InheritanceFlags 値のいずれか。

propagationFlags
PropagationFlags

子オブジェクトにアクセス制御エントリ (ACE) を反映する方法を指定する PropagationFlags 値のいずれか。

type
AccessControlType

操作を許可するか拒否するかを指定する AccessControlType 値のいずれか。

例外

identity パラメーターが null です。

type パラメーターに誤った列挙体が渡されました。

  • または - inheritanceFlags パラメーターに誤った列挙体が渡されました。

  • または - propagationFlags パラメーターに誤った列挙体が渡されました。

注釈

このコンストラクターを使用して、またはDirectorySecurityクラスを使用して永続化できるアクセス制御規則をFileSecurity作成します。 アクセス制御規則では、Microsoft Windows を実行しているコンピューターで許可または禁止されるアクションを決定するユーザー アカウント権限を定義します。

このパラメーターは identity 、現在のコンピューターまたはドメイン上の有効なアカウントを識別する必要があります。 この文字列は、有効なドメインまたはコンピューター名の名前でaccountDOMAINドメインまたはコンピューターDOMAIN\account上の有効なユーザー アカウントの名前を表す次の形式になります。

適用対象