如何創建/編輯/添加文件夾權限到特定文件夾?本地磁盤C中有一個名爲「test」的文件夾。如何使用C#將權限設置爲該文件夾?如何設置文件夾權限
我寫了一些代碼已經:
public void getusers()
{
SelectQuery squery = new SelectQuery("Win32_UserAccount", "Domain='" + System.Environment.UserDomainName.ToString() + "'");
try
{
ManagementObjectSearcher msearchar = new ManagementObjectSearcher(squery);
foreach (ManagementObject mobject in msearchar.Get())
{
comboBox1.Items.Add(mobject["Name"]);
}
}
catch (Exception e) { MessageBox.Show(e.ToString()); }
}
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
fbd.ShowDialog();
textBox1.Text = fbd.SelectedPath.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
DirectoryInfo myDirectoryInfo = new DirectoryInfo(textBox1.Text);
DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
string User = System.Environment.UserDomainName + "\\" + comboBox1.SelectedItem.ToString();
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow));
//myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User, FileSystemRights.Write, InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow));
myDirectoryInfo.SetAccessControl(myDirectorySecurity);
MessageBox.Show("Permissions Altered Successfully" + User);
}
此代碼已經成功地將用戶添加到該文件夾,但設置該文件夾的permissionIi不被繼承的。我錯過了什麼?或者有人可以指導我如何繼承該文件夾的權限?
請不要在「C#」等前加上標題。這就是標籤的用途。 – 2012-02-10 03:19:26