4
C# .NET에서 NTFS 사용 권한을 설정하는 방법은 무엇입니까? .NET에서 읽기/쓰기 권한을 변경하려고합니다. 나는 초보자입니다. 제발 도와주세요!C# .NET에서 NTFS 사용 권한 설정
C# .NET에서 NTFS 사용 권한을 설정하는 방법은 무엇입니까? .NET에서 읽기/쓰기 권한을 변경하려고합니다. 나는 초보자입니다. 제발 도와주세요!C# .NET에서 NTFS 사용 권한 설정
System.Security.AccessControl 이름 공간으로 수행 할 수 있어야합니다.
System.Security.AccessControl;
public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
// Create a new DirectoryInfo object.
DirectoryInfo dInfo = new DirectoryInfo(FileName);
// 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, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None,
ControlType));
// Set the new access settings.
dInfo.SetAccessControl(dSecurity);
}
예 전화는 :
//Get current user
string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
//Deny writing to the file
AddDirectorySecurity(@"C:\Users\Phil\Desktop\hello.ini",user, FileSystemRights.Write, AccessControlType.Deny);
acutally 일이! –
당신은 매우 환영합니다 – ApolloSoftware
AmitApollo! –