Tôi đang cố gắng cấp quyền truy cập thư mục cho người dùng, nhưng khi tôi đang cố gắng chạy chương trình, lỗi nói: Some or all identity references could not be translated
.Không thể dịch một số hoặc tất cả các tham chiếu nhận dạng C#
Đây là mã mà tôi đang sử dụng:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Security;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Management;
using System.Management.Instrumentation;
namespace FolderLock
{
public partial class Lock : Form
{
public Lock()
{
InitializeComponent();
SetAccess();
}
private void Lock_Load(object sender, EventArgs e)
{
}
public void SetAccess()
{
DirectoryInfo myDirectoryInfo = new DirectoryInfo("C:/Users/Trov/Desktop/Test");
DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
string User = System.Environment.UserDomainName + "\\" + "92111092";
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.Read, AccessControlType.Deny));
myDirectoryInfo.SetAccessControl(myDirectorySecurity);
}
}
}
Những dòng được không? –
dòng này thưa ngài: 'myDirectorySecurity.AddAccessRule (FileSystemAccessRule mới (User, FileSystemRights.Read, AccessControlType.Deny));' – Kaoru
Phiên bản hệ điều hành nào? –