Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
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

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.Runtime.InteropServices.CallingConvention
System.Runtime.InteropServices.CharSet
System.Security.Permissions.FileIOPermission




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734