728x90
반응형
728x170
■ Directory 클래스의 GetAccessControl 정적 메소드를 사용해 디렉토리 권한을 체크하는 방법을 보여준다.
▶ Directory 클래스 : GetAccessControl 정적 메소드를 사용해 디렉토리 권한 체크하기 예제 (C#)
using System;
Console.WriteLine(CheckDirectoryPermission("c:\\Temp", FileSystemRights.Write));
▶ Directory 클래스 : GetAccessControl 정적 메소드를 사용해 디렉토리 권한 체크하기 (C#)
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;
#region 디렉토리 권한 체크하기 - CheckDirectoryPermission(directoryPath, fileSystemRights)
/// <summary>
/// 디렉토리 권한 체크하기
/// </summary>
/// <param name="directoryPath">디렉토리 경로</param>
/// <param name="fileSystemRights">파일 시스템 권한</param>
/// <returns>디렉토리 권한 체크 결과</returns>
public bool CheckDirectoryPermission(string directoryPath, FileSystemRights fileSystemRights)
{
if(string.IsNullOrEmpty(directoryPath))
{
return false;
}
try
{
AuthorizationRuleCollection ruleCollection = Directory.GetAccessControl(directoryPath).GetAccessRules(true, true, typeof(SecurityIdentifier));
WindowsIdentity identity = WindowsIdentity.GetCurrent();
foreach(FileSystemAccessRule rule in ruleCollection)
{
if(identity.Groups.Contains(rule.IdentityReference))
{
if((fileSystemRights & rule.FileSystemRights) == fileSystemRights)
{
if(rule.AccessControlType == AccessControlType.Allow)
{
return true;
}
}
}
}
}
catch
{
}
return false;
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON/.NET6] DateTime 구조체 : ParseExact 정적 메소드를 사용해 ISO 8601 날짜 포맷 문자열에서 DateTime 객체 구하기 (0) | 2022.10.24 |
---|---|
[C#/COMMON/.NET6] DateTime 구조체 : Parse 정적 메소드를 사용해 ISO 8601 날짜 포맷 문자열에서 DateTime 객체 구하기 (0) | 2022.10.24 |
[C#/COMMON/.NET6] Process 클래스 : 부모 프로세스 종료시 자식 프로세스 종료시키기 (0) | 2022.10.24 |
[C#/COMMON/.NET6] Uri 클래스 : Host 속성을 사용해 도메인 호스트 구하기 (0) | 2022.10.23 |
[C#/COMMON] Directory 클래스 : GetAccessControl 정적 메소드를 사용해 디렉토리 쓰기 권한 체크하기 (0) | 2022.10.23 |
[C#/COMMON/.NET6] File 클래스 : Create 정적 메소드를 사용해 디렉토리 쓰기 가능 여부 구하기 (0) | 2022.10.23 |
[C#/COMMON/.NET6] 64비트 운영 체제 여부 구하기 (0) | 2022.10.22 |
[C#/COMMON/.NET6] 64비트 운영 체제 여부 구하기 (0) | 2022.10.22 |
[C#/COMMON/.NET6] 64비트 프로세스 여부/64비트 운영 체제 여부 구하기 (0) | 2022.10.21 |
[C#/COMMON] 파일 서명 기반으로 파일 MIME 타입 구하기 (0) | 2022.10.21 |
댓글을 달아 주세요