File.GetAccessControl 메서드

정의

지정된 파일에 대한 ACL(액세스 제어 목록) 항목을 캡슐화하는 FileSecurity 개체를 가져옵니다.

오버로드

GetAccessControl(String)

지정된 파일에 대한 ACL(액세스 제어 목록) 항목을 캡슐화하는 FileSecurity 개체를 가져옵니다.

GetAccessControl(String, AccessControlSections)

특정 파일에 대해 지정된 형식의 ACL(액세스 제어 목록) 항목을 캡슐화하는 FileSecurity 개체를 가져옵니다.

설명

메서드를 GetAccessControl 사용하여 지정된 파일에 대한 ACL(액세스 제어 목록) 항목을 검색합니다.

GetAccessControl(String)

지정된 파일에 대한 ACL(액세스 제어 목록) 항목을 캡슐화하는 FileSecurity 개체를 가져옵니다.

public:
 static System::Security::AccessControl::FileSecurity ^ GetAccessControl(System::String ^ path);
public static System.Security.AccessControl.FileSecurity GetAccessControl (string path);
static member GetAccessControl : string -> System.Security.AccessControl.FileSecurity
Public Shared Function GetAccessControl (path As String) As FileSecurity

매개 변수

path
String

파일의 ACL(액세스 제어 목록) 정보를 설명하는 FileSecurity 개체가 포함된 파일의 경로입니다.

반환

FileSecurity

FileSecurity 매개 변수에 설명된 파일의 액세스 제어 규칙을 캡슐화하는 path 개체입니다.

예외

파일을 여는 동안 I/O 오류가 발생했습니다.

path 매개 변수가 null인 경우

파일을 찾을 수 없습니다.

path 매개 변수가 읽기 전용 파일을 지정합니다.

또는 현재 플랫폼이 해당 작업을 지원하지 않는 경우

또는 path 매개 변수가 디렉터리를 지정합니다.

또는 호출자에게 필요한 권한이 없는 경우

예제

다음 코드 예제에서는 파일에서 GetAccessControl ACL(액세스 제어 목록) 항목을 추가 및 제거하기 위해 메서드와 SetAccessControl 메서드를 사용합니다. 이 예제를 실행하려면 유효한 사용자 또는 그룹 계정을 제공해야 합니다.

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

설명

이 메서드를 GetAccessControl 사용하여 파일에 대한 ACL(액세스 제어 목록) 항목을 검색합니다.

ACL은 지정된 파일에 대한 특정 작업에 대한 권한이 있거나 없는 개인 및/또는 그룹을 설명합니다. 자세한 내용은 방법: 액세스 제어 목록 항목 추가 또는 제거를 참조하세요.

NTFS 환경에서 ReadAttributes ReadExtendedAttributes 는 사용자에게 부모 폴더에 대한 권한이 있는 경우 사용자에게 ListDirectory 부여됩니다. 거부 ReadAttributes 하려면 ReadExtendedAttributes부모 디렉터리에 대해 거부 ListDirectory 합니다.

적용 대상

GetAccessControl(String, AccessControlSections)

특정 파일에 대해 지정된 형식의 ACL(액세스 제어 목록) 항목을 캡슐화하는 FileSecurity 개체를 가져옵니다.

public:
 static System::Security::AccessControl::FileSecurity ^ GetAccessControl(System::String ^ path, System::Security::AccessControl::AccessControlSections includeSections);
public static System.Security.AccessControl.FileSecurity GetAccessControl (string path, System.Security.AccessControl.AccessControlSections includeSections);
static member GetAccessControl : string * System.Security.AccessControl.AccessControlSections -> System.Security.AccessControl.FileSecurity
Public Shared Function GetAccessControl (path As String, includeSections As AccessControlSections) As FileSecurity

매개 변수

path
String

파일의 ACL(액세스 제어 목록) 정보를 설명하는 FileSecurity 개체가 포함된 파일의 경로입니다.

includeSections
AccessControlSections

가져올 ACL(액세스 제어 목록) 정보의 형식을 지정하는 AccessControlSections 값 중 하나입니다.

반환

FileSecurity

FileSecurity 매개 변수에 설명된 파일의 액세스 제어 규칙을 캡슐화하는 path 개체입니다.

예외

파일을 여는 동안 I/O 오류가 발생했습니다.

path 매개 변수가 null인 경우

파일을 찾을 수 없습니다.

path 매개 변수가 읽기 전용 파일을 지정합니다.

또는 현재 플랫폼이 해당 작업을 지원하지 않는 경우

또는 path 매개 변수가 디렉터리를 지정합니다.

또는 호출자에게 필요한 권한이 없는 경우

설명

이 메서드를 GetAccessControl 사용하여 파일에 대한 ACL(액세스 제어 목록) 항목을 검색합니다.

ACL은 지정된 파일에 대한 특정 작업에 대한 권한이 있거나 없는 개인 및/또는 그룹을 설명합니다. 자세한 내용은 방법: 액세스 제어 목록 항목 추가 또는 제거를 참조하세요.

NTFS 환경에서 ReadAttributes ReadExtendedAttributes 는 사용자에게 부모 폴더에 대한 권한이 있는 경우 사용자에게 ListDirectory 부여됩니다. 거부 ReadAttributes 하려면 ReadExtendedAttributes부모 디렉터리에 대해 거부 ListDirectory 합니다.

적용 대상