changing the user group permission to full control.

Sep 6, 2010 at 12:37 PM

hi all,

i have a requirement to change the permission of  group  (windows\users)  to full control using C# to some set of application folder.

i mean, if u right click on any folder properties, in security tab, u have Users Group.

for this i need to give full control permission programatically.

 

 

List<string> users = new List<string>();

 

SelectQuery Squery = new SelectQuery("Win32_Group", "Domain='" + System.Environment.MachineName.ToString() + "'");

 

ManagementObjectSearcher mos = new ManagementObjectSearcher(Squery);

 

foreach (ManagementObject mobj in mos.Get())

{

comboBox1.Items.Add(mobj[

"Name"].ToString());

users.Add(mobj[

"Name"].ToString());

}

 

 

FileStream fs = new FileStream("FolderPath.txt", FileMode.Open, FileAccess.Read);

 

StreamReader reader = new StreamReader(fs);

 

while ((strFolderpath = reader.ReadLine()) != null)

{

 

for (int i = 0; i < users.Count(); i++)

{

 

DirectoryInfo myDirectoryinfo = new DirectoryInfo(strFolderpath.ToString());

 

DirectorySecurity mydirectorySec = myDirectoryinfo.GetAccessControl();

 

string user = System.Environment.MachineName + '\\' + users[i].ToString();

mydirectorySec.AddAccessRule(

new FileSystemAccessRule(user, FileSystemRights.FullControl, AccessControlType.Allow));

myDirectoryinfo.SetAccessControl(mydirectorySec);

}

}

trying to do like this but i think we cannot pass user group, may be we need to pass user name.

need solution.

please help.

thank you.