DirectoryInfo.GetAccessControl 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 디렉터리의 ACL(액세스 제어 목록) 항목을 가져옵니다.
오버로드
GetAccessControl() |
현재 DirectorySecurity 개체에서 설명하는 디렉터리의 ACL(액세스 제어 목록) 항목을 캡슐화하는 DirectoryInfo 개체를 가져옵니다. |
GetAccessControl(AccessControlSections) |
현재 DirectorySecurity 개체에서 설명하는 디렉터리의 지정된 ACL(액세스 제어 목록) 항목 형식을 캡슐화하는 DirectoryInfo 개체를 가져옵니다. |
설명
메서드를 사용하여 GetAccessControl 현재 파일에 대한 ACL(액세스 제어 목록) 항목을 검색합니다.
자세한 내용은 방법: 액세스 제어 목록 항목 추가 또는 제거를 참조하세요.
GetAccessControl()
현재 DirectorySecurity 개체에서 설명하는 디렉터리의 ACL(액세스 제어 목록) 항목을 캡슐화하는 DirectoryInfo 개체를 가져옵니다.
public:
System::Security::AccessControl::DirectorySecurity ^ GetAccessControl();
public System.Security.AccessControl.DirectorySecurity GetAccessControl ();
member this.GetAccessControl : unit -> System.Security.AccessControl.DirectorySecurity
Public Function GetAccessControl () As DirectorySecurity
반환
디렉터리의 액세스 제어 규칙을 캡슐화하는 DirectorySecurity 개체입니다.
예외
디렉터리를 찾거나 수정할 수 없는 경우
디렉터리를 여는 동안 I/O 오류가 발생한 경우
예제
다음 예제에서는 및 SetAccessControl 메서드를 사용하여 GetAccessControl 디렉터리에서 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 호출하고 액세스 제어 섹션AccessControlSections.OwnerAccessControlSections.Group | AccessControlSections.Access | (AccessControlSections.GroupAccessControlSections.AccessOr
AccessControlSections.OwnerOr
Visual Basic의 경우)을 지정하는 것과 같습니다.
메서드를 GetAccessControl 사용하여 현재 파일에 대한 ACL(액세스 제어 목록) 항목을 검색합니다.
ACL은 지정된 파일 또는 디렉터리에 대한 특정 작업에 대한 권한이 있거나 없는 개인 및/또는 그룹에 대해 설명합니다. 자세한 내용은 방법: 액세스 제어 목록 항목 추가 또는 제거를 참조하세요.
적용 대상
GetAccessControl(AccessControlSections)
현재 DirectorySecurity 개체에서 설명하는 디렉터리의 지정된 ACL(액세스 제어 목록) 항목 형식을 캡슐화하는 DirectoryInfo 개체를 가져옵니다.
public:
System::Security::AccessControl::DirectorySecurity ^ GetAccessControl(System::Security::AccessControl::AccessControlSections includeSections);
public System.Security.AccessControl.DirectorySecurity GetAccessControl (System.Security.AccessControl.AccessControlSections includeSections);
member this.GetAccessControl : System.Security.AccessControl.AccessControlSections -> System.Security.AccessControl.DirectorySecurity
Public Function GetAccessControl (includeSections As AccessControlSections) As DirectorySecurity
매개 변수
- includeSections
- AccessControlSections
가져올 ACL(액세스 제어 목록) 정보의 형식을 지정하는 AccessControlSections 값 중 하나입니다.
반환
DirectorySecurity 매개 변수에 설명된 파일의 액세스 제어 규칙을 캡슐화하는 path
개체입니다.
예외
디렉터리를 찾거나 수정할 수 없는 경우
현재 프로세스에 디렉터리를 열 수 있는 권한이 없는 경우
또는
디렉터리가 읽기 전용인 경우
또는
현재 플랫폼이 해당 작업을 지원하지 않는 경우
또는
호출자에게 필요한 권한이 없는 경우
디렉터리를 여는 동안 I/O 오류가 발생한 경우
설명
메서드를 GetAccessControl 사용하여 현재 파일에 대한 ACL(액세스 제어 목록) 항목을 검색합니다.
ACL은 지정된 파일 또는 디렉터리에 대한 특정 작업에 대한 권한이 있거나 없는 개인 및/또는 그룹에 대해 설명합니다. 자세한 내용은 방법: 액세스 제어 목록 항목 추가 또는 제거를 참조하세요.
적용 대상
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기