Here is the code I used:
using system;
using system.Management;
using system.Management.Instrumentation;
using system.Security.AccessControl;
namespace Permissions
{
public static int Main(string[] args)
{
string strFolderPath = "c:\\Program Files\\Whaddeva\\";
string strUserName = "user@domain";
AddDirectorySecurity(strFolderPath, strUserName, FileSystemRights.FullControl, AccessControlType.Allow);
}
public static void AddDirectorySecurity(string Filename, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
DirectoryInfo dInfo = new DirectoryInfo(Filename);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule(Account, Rights, ControlType));
dInfo.SetAccessControl(dSecurity);
}
}
The code doesn't exactly grant Full Control, but rather grants Special Permissions which effectively grant full control.
Now, since the effective permissions allow Full Control, one would expect the user to have permissions, right?
Wrong.
User gets 'access denied,' for some reason.
Ideas, anyone?