2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Security.AccessControl;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string Directoryd = "D:";
            string mydirectory = Directoryd + "\\" + "rs\\";
            if (!Directory.Exists(mydirectory))
            {
                Directory.CreateDirectory(mydirectory); 
            }
            DirectoryInfo di = new DirectoryInfo(mydirectory);
            DirectorySecurity ds = di.GetAccessControl();


            ds.AddAccessRule(new FileSystemAccessRule(@"*",FileSystemRights.FullControl,AccessControlType.Allow));
           di.SetAccessControl(ds);





        }
    }
}

这是我的代码,当我执行此操作时,弹出窗口显示实际上,此代码是创建一个文件夹 rs 并将其权限设置为拒绝完全控制但在运行时出现错误消息 Some or all identity references could not be translate . 错误是什么?

4

2 回答 2

2

您应该更改以下行:

 ds.AddAccessRule(new FileSystemAccessRule(@"*",FileSystemRights.FullControl,AccessControlType.Allow));

到:

 ds.AddAccessRule(new FileSystemAccessRule(@"Everyone",FileSystemRights.FullControl,AccessControlType.Allow));

此外,如果您查看以下每个人组,则在下面有一个答案,建议您应该使用 SSID 而不是名称。

于 2012-07-13T15:01:47.723 回答
1

尝试组“每个人”,而不是 *。

于 2012-07-13T15:00:03.303 回答