C# Application can't read/write to files created by administrator when run in limited user account XP

梦想的初衷 提交于 2019-12-03 03:46:28

Yeah, it's the SetAccessControl method all right, there is a good example here (the post from satankidneypie)

Good luck

I think SetAccessControl is the way to go. Maybe something like this:

// get the existing access controls
FileSecurity fs = File.GetAccessControl(yourFilename);

// add the new rule to the existing settings
fs.AddAccessRule(new FileSystemAccessRule(
    @"DOMAIN\Users",  // or "BUILTIN\Users", "COMPUTER\AccountName" etc
    FileSystemRights.Modify,
    AccessControlType.Allow));

// set the updated access controls
File.SetAccessControl(yourFilename, fs);

Note: It's important that you get the existing access control list from the file and then add your new rule to that. If you just create a new access control list from scratch then it will overwrite the existing permissions completely.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!