Directory.GetAccessControl 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
디렉터리의 Windows ACL(액세스 제어 목록)을 반환합니다.
오버로드
GetAccessControl(String) |
지정된 디렉터리의 ACL(액세스 제어 목록) 항목을 캡슐화하는 DirectorySecurity 개체를 가져옵니다. |
GetAccessControl(String, AccessControlSections) |
지정된 디렉터리의 지정된 ACL(액세스 제어 목록) 항목 형식을 캡슐화하는 DirectorySecurity 개체를 가져옵니다. |
GetAccessControl(String)
지정된 디렉터리의 ACL(액세스 제어 목록) 항목을 캡슐화하는 DirectorySecurity 개체를 가져옵니다.
public:
static System::Security::AccessControl::DirectorySecurity ^ GetAccessControl(System::String ^ path);
public static System.Security.AccessControl.DirectorySecurity GetAccessControl (string path);
static member GetAccessControl : string -> System.Security.AccessControl.DirectorySecurity
Public Shared Function GetAccessControl (path As String) As DirectorySecurity
매개 변수
- path
- String
파일의 ACL(액세스 제어 목록) 정보를 설명하는 DirectorySecurity 개체가 포함된 디렉터리의 경로입니다.
반환
path
매개 변수에 설명된 파일의 액세스 제어 규칙을 캡슐화하는 개체입니다.
예외
path
매개 변수가 null
인 경우
디렉터리를 여는 동안 I/O 오류가 발생한 경우
시스템 수준 오류가(예: 디렉터리를 찾을 수 없음) 발생했습니다. 특정 예외가 SystemException의 하위 클래스일 수 있습니다.
path
매개 변수가 읽기 전용 디렉터리를 지정합니다.
또는
현재 플랫폼이 해당 작업을 지원하지 않는 경우
또는
호출자에게 필요한 권한이 없는 경우
예제
다음 예제에서는 및 SetAccessControl 메서드를 사용하여 GetAccessControl ACL(액세스 제어 목록) 항목을 추가한 다음 디렉터리에서 ACL 항목을 제거합니다. 이 예제를 실행하려면 유효한 사용자 또는 그룹 계정을 제공해야 합니다.
using namespace System;
using namespace System::IO;
using namespace System::Security::AccessControl;
// Adds an ACL entry on the specified directory for the
// specified account.
void AddDirectorySecurity(String^ directoryName, String^ account,
FileSystemRights rights, AccessControlType controlType)
{
// Create a new DirectoryInfo object.
DirectoryInfo^ dInfo = gcnew DirectoryInfo(directoryName);
// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity^ dSecurity = dInfo->GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
dSecurity->AddAccessRule( gcnew FileSystemAccessRule(account,
rights, controlType));
// Set the new access settings.
dInfo->SetAccessControl(dSecurity);
}
// Removes an ACL entry on the specified directory for the
// specified account.
void RemoveDirectorySecurity(String^ directoryName, String^ account,
FileSystemRights rights, AccessControlType controlType)
{
// Create a new DirectoryInfo object.
DirectoryInfo^ dInfo = gcnew DirectoryInfo(directoryName);
// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity^ dSecurity = dInfo->GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
dSecurity->RemoveAccessRule(gcnew FileSystemAccessRule(account,
rights, controlType));
// Set the new access settings.
dInfo->SetAccessControl(dSecurity);
}
int main()
{
String^ directoryName = "TestDirectory";
String^ accountName = "MYDOMAIN\\MyAccount";
if (!Directory::Exists(directoryName))
{
Console::WriteLine("The directory {0} could not be found.",
directoryName);
return 0;
}
try
{
Console::WriteLine("Adding access control entry for {0}",
directoryName);
// Add the access control entry to the directory.
AddDirectorySecurity(directoryName, accountName,
FileSystemRights::ReadData, AccessControlType::Allow);
Console::WriteLine("Removing access control entry from {0}",
directoryName);
// Remove the access control entry from the directory.
RemoveDirectorySecurity(directoryName, accountName,
FileSystemRights::ReadData, AccessControlType::Allow);
Console::WriteLine("Done.");
}
catch (UnauthorizedAccessException^)
{
Console::WriteLine("You are not authorised to carry" +
" out this procedure.");
}
catch (System::Security::Principal::
IdentityNotMappedException^)
{
Console::WriteLine("The account {0} could not be found.", accountName);
}
}
using System;
using System.IO;
using System.Security.AccessControl;
namespace FileSystemExample
{
class DirectoryExample
{
public static void Main()
{
try
{
string DirectoryName = "TestDirectory";
Console.WriteLine("Adding access control entry for " + DirectoryName);
// Add the access control entry to the directory.
AddDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow);
Console.WriteLine("Removing access control entry from " + DirectoryName);
// Remove the access control entry from the directory.
RemoveDirectorySecurity(DirectoryName, @"MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow);
Console.WriteLine("Done.");
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadLine();
}
// Adds an ACL entry on the specified directory for the specified account.
public static void AddDirectorySecurity(string DirectoryName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(DirectoryName);
// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
Rights,
ControlType));
// Set the new access settings.
dInfo.SetAccessControl(dSecurity);
}
// Removes an ACL entry on the specified directory for the specified account.
public static void RemoveDirectorySecurity(string DirectoryName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(DirectoryName);
// Get a DirectorySecurity object that represents the
// current security settings.
DirectorySecurity dSecurity = dInfo.GetAccessControl();
// Add the FileSystemAccessRule to the security settings.
dSecurity.RemoveAccessRule(new FileSystemAccessRule(Account,
Rights,
ControlType));
// Set the new access settings.
dInfo.SetAccessControl(dSecurity);
}
}
}
open System
open System.IO
open System.Security.AccessControl
// Adds an ACL entry on the specified directory for the specified account.
let addDirectorySecurity fileName (account: string) rights controlType =
// Create a new DirectoryInfo object.
let dInfo = DirectoryInfo fileName
// Get a DirectorySecurity object that represents the
// current security settings.
let dSecurity = dInfo.GetAccessControl()
// Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(FileSystemAccessRule(account, rights, controlType))
// Set the new access settings.
dInfo.SetAccessControl dSecurity
// Removes an ACL entry on the specified directory for the specified account.
let removeDirectorySecurity fileName (account: string) rights controlType =
// Create a new DirectoryInfo object.
let dInfo = DirectoryInfo fileName
// Get a DirectorySecurity object that represents the
// current security settings.
let dSecurity = dInfo.GetAccessControl()
// Add the FileSystemAccessRule to the security settings.
dSecurity.RemoveAccessRule(FileSystemAccessRule(account, rights, controlType)) |> ignore
// Set the new access settings.
dInfo.SetAccessControl dSecurity
try
let DirectoryName = "TestDirectory"
printfn $"Adding access control entry for {DirectoryName}"
// Add the access control entry to the directory.
addDirectorySecurity DirectoryName @"MYDOMAIN\MyAccount" FileSystemRights.ReadData AccessControlType.Allow
printfn $"Removing access control entry from {DirectoryName}"
// Remove the access control entry from the directory.
removeDirectorySecurity DirectoryName @"MYDOMAIN\MyAccount" FileSystemRights.ReadData AccessControlType.Allow
printfn "Done."
with e ->
printfn $"{e}"
Imports System.IO
Imports System.Security.AccessControl
Module DirectoryExample
Sub Main()
Try
Dim DirectoryName As String = "TestDirectory"
Console.WriteLine("Adding access control entry for " + DirectoryName)
' Add the access control entry to the directory.
AddDirectorySecurity(DirectoryName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow)
Console.WriteLine("Removing access control entry from " + DirectoryName)
' Remove the access control entry from the directory.
RemoveDirectorySecurity(DirectoryName, "MYDOMAIN\MyAccount", FileSystemRights.ReadData, AccessControlType.Allow)
Console.WriteLine("Done.")
Catch e As Exception
Console.WriteLine(e)
End Try
Console.ReadLine()
End Sub
' Adds an ACL entry on the specified directory for the specified account.
Sub AddDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
' Create a new DirectoryInfoobject.
Dim dInfo As New DirectoryInfo(FileName)
' Get a DirectorySecurity object that represents the
' current security settings.
Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
' Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(New FileSystemAccessRule(Account, Rights, ControlType))
' Set the new access settings.
dInfo.SetAccessControl(dSecurity)
End Sub
' Removes an ACL entry on the specified directory for the specified account.
Sub RemoveDirectorySecurity(ByVal FileName As String, ByVal Account As String, ByVal Rights As FileSystemRights, ByVal ControlType As AccessControlType)
' Create a new DirectoryInfo object.
Dim dInfo As New DirectoryInfo(FileName)
' Get a DirectorySecurity object that represents the
' current security settings.
Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()
' Add the FileSystemAccessRule to the security settings.
dSecurity.RemoveAccessRule(New FileSystemAccessRule(Account, Rights, ControlType))
' Set the new access settings.
dInfo.SetAccessControl(dSecurity)
End Sub
End Module
설명
메서드를 GetAccessControl 사용하여 디렉터리에 대한 ACL(액세스 제어 목록) 항목을 검색합니다.
ACL은 지정된 파일 또는 디렉터리에 대한 특정 작업에 대한 권한이 있거나 없는 개인 및/또는 그룹에 대해 설명합니다. 자세한 내용은 방법: 액세스 제어 목록 항목 추가 또는 제거를 참조하세요.
NTFS 환경에서 ReadAttributes 는 ReadExtendedAttributes 사용자에게 부모 폴더에 대한 권한이 있는 경우 사용자에게 ListDirectory 부여됩니다. 및 ReadExtendedAttributes를 거부 ReadAttributes 하려면 부모 디렉터리에서 를 거부 ListDirectory 합니다.
적용 대상
GetAccessControl(String, AccessControlSections)
지정된 디렉터리의 지정된 ACL(액세스 제어 목록) 항목 형식을 캡슐화하는 DirectorySecurity 개체를 가져옵니다.
public:
static System::Security::AccessControl::DirectorySecurity ^ GetAccessControl(System::String ^ path, System::Security::AccessControl::AccessControlSections includeSections);
public static System.Security.AccessControl.DirectorySecurity GetAccessControl (string path, System.Security.AccessControl.AccessControlSections includeSections);
static member GetAccessControl : string * System.Security.AccessControl.AccessControlSections -> System.Security.AccessControl.DirectorySecurity
Public Shared Function GetAccessControl (path As String, includeSections As AccessControlSections) As DirectorySecurity
매개 변수
- path
- String
파일의 ACL(액세스 제어 목록) 정보를 설명하는 DirectorySecurity 개체가 포함된 디렉터리의 경로입니다.
- includeSections
- AccessControlSections
가져올 ACL(액세스 제어 목록) 정보의 형식을 지정하는 AccessControlSections 값 중 하나입니다.
반환
path
매개 변수에 설명된 파일의 액세스 제어 규칙을 캡슐화하는 개체입니다.
예외
path
매개 변수가 null
인 경우
디렉터리를 여는 동안 I/O 오류가 발생한 경우
시스템 수준 오류가(예: 디렉터리를 찾을 수 없음) 발생했습니다. 특정 예외가 SystemException의 하위 클래스일 수 있습니다.
path
매개 변수가 읽기 전용 디렉터리를 지정합니다.
또는
현재 플랫폼이 해당 작업을 지원하지 않는 경우
또는
호출자에게 필요한 권한이 없는 경우
설명
메서드를 GetAccessControl 사용하여 디렉터리에 대한 ACL(액세스 제어 목록) 항목을 검색합니다.
ACL은 지정된 파일 또는 디렉터리에 대한 특정 작업에 대한 권한이 있거나 없는 개인 및/또는 그룹에 대해 설명합니다. 자세한 내용은 방법: 액세스 제어 목록 항목 추가 또는 제거를 참조하세요.
NTFS 환경에서 ReadAttributes 는 ReadExtendedAttributes 사용자에게 부모 폴더에 대한 권한이 있는 경우 사용자에게 ListDirectory 부여됩니다. 및 ReadExtendedAttributes를 거부 ReadAttributes 하려면 부모 디렉터리에서 를 거부 ListDirectory 합니다.
적용 대상
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기