|
| Setting ACL File Attributes with C# |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.security.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| Michael Lierheimer |
Hallo all.
We need to set file and directory security rights to specific NT roles, so that all member of the role can access them within Internet Explorer. We create the file as administrator and have to change the security. How can we do this within .NET? The file attributes set by the class FileIOPermission are non permanent, or? So which class can or should be used?
Michael Lierheimer MCSD
|
|
|
| |
|
| |
| |
| Shawn Farkas [MS] (VIP) |
Michael,
Version 1 of the .net framework does not have built in support for ACLs. If you go to the gotdotnet page (http://www.gotdotnet.com/team/csharp/code/default.aspx), you will see that there is a library there that you can use within your managed apps to deal with NTFS ACLs and ACEs.
-Shawn
-- This posting is provided "AS IS" with no warranties, and confers no rights. Please do not send email directly to this alias, this alias is for newsgroup purposes only.
"Michael Lierheimer" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Michael Lierheimer |
Thanks Shwan.
That was it, excactly what I looked for. I only missed a function to set the DACL on the file, but that was easy.
Yours Michael
"Shawn Farkas [MS]" <Click here to reveal e-mail address> schrieb im Newsbeitrag news:ucTJ3N51CHA.1656@TK2MSFTNGP09... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| Stuart Clement |
Hi Michael,
how did you get it working? I have a directory that I want to set the permissions so that any authenticated user of the system can read, write, delete etc... to any sub-directory or file. Here's what I've some up with so far. I'm not sure I'm even anywhere near the mark.
thanks in advance
Stu
-----------------------------------------
string filename = @"C:\WorkingDir";
SecurityDescriptor secDesc = SecurityDescriptor.GetFileSecurity( filename, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION);
using(secDesc) { Dacl dacl = secDesc.Dacl; dacl.AddAce(new AceAccessAllowed(Sids.AuthenticatedUser, AccessType.GENERIC_ALL)); secDesc.SetDacl(dacl); secDesc.MakeAbsolute(); }
Michael Lierheimer wrote: [Original message clipped]
|
|
|
| |
|
| |
| |
| Michael Lierheimer |
Hallo Stuart.
You need to save the new DACL to the file with SetFileSecurity, see the following Import statement. I am still in testing the classes, so I cannot tell if it works in all situations.
[DllImport(Advapi32, CallingConvention=CallingConvention.Winapi, SetLastError=true, CharSet=CharSet.Auto)] public static extern BOOL SetFileSecurity( LPCTSTR lpFileName, // file name SECURITY_INFORMATION SecurityInformation, // contents PSECURITY_DESCRIPTOR pSecurityDescriptor // SD );
Yours Michael
"Stuart Clement" <Click here to reveal e-mail address> schrieb im Newsbeitrag news:Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
| |
| |
| Stuart Clement |
Michael,
thanks for that. I've added the call you said and it works a treat. :o)
cheers
Stu
Michael Lierheimer wrote: [Original message clipped]
|
|
|
| |
|
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|