简体   繁体   中英

Can not add access rules with WellKnownSidType.WorldSid on windows 7

Here is the code:

var sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
var directorySecurity = new DirectorySecurity();
directorySecurity.AddAccessRule(new FileSystemAccessRule(sid, FileSystemRights.FullControl, AccessControlType.Allow));
Directory.CreateDirectory(Path.GetDirectoryName(this.PathToSettings.LocalPath), directorySecurity);
var fileSecurity = new FileSecurity();
fileSecurity.AddAccessRule(new FileSystemAccessRule(sid, FileSystemRights.FullControl, AccessControlType.Allow));
using (var fs = new FileStream(this.PathToSettings.LocalPath, FileMode.Create,     FileSystemRights.FullControl, FileShare.None, 1024, FileOptions.None, fileSecurity))
{
    var bytes = Encoding.UTF8.GetBytes(Resources.DefaultSettings);
    fs.Write(bytes, 0, bytes.Length);
}

The problem: on windows 7 these access rules does not apply to file (I do not see group Everyone on Security page of the file properties dialog.

I want to allow access to specified file for everyone (admins, users, whatever).

What I'm doing incorrectly?

The problem was in a class that saves settings - it removes old file and creates new (using default security rules). Very stupid, don't know why someone wrote such code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM