Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting file permissions with C#

Status
Not open for further replies.

khrispy

Programmer
Dec 11, 2003
1
US
How does one set file permissions in C#? My C# Windows
application needs to be able to set read/write permissions
on some files for specified groups, users, and/or 'everyone'. How is this done?

Any code examples would also be helpful as I am new to C#.

Thanks.

 
Take a look to FileStream , FileAcess and FileShare but I think you are talking about:
(DACL) An access control list that is controlled by the owner of an object and that specifies the access particular users or groups can have to the object.
(ACL) A list of security protections that applies to an object. (An object can be a file, process, event, or anything else having a security descriptor.) An entry in an access control list (ACL) is an access control entry (ACE). There are two types of access control list, discretionary and system.
(ACE) An entry in an access control list (ACL). An ACE contains a set of access rights and a security identifier (SID) that identifies a trustee for whom the rights are allowed, denied, or audited.
(SID) A structure of variable length that uniquely identifies a user or group on all Windows NT implementations.
And more ...

For example, to get a Security Token
Code:
using System.Runtime.InteropServices;    //DllImport "kernel32.dll", "advapi32.dll" ...
....
[DllImport("advapi32.dll")]
private static extern bool LogonUser(
            String lpszUsername,
            String lpszDomain,
            String lpszPassword,
            int dwLogonType,
            int dwLogonProvider,
            ref IntPtr phToken   
            );
There are a lot of functions to deal with that. 

GetAclInformation()
GetAce()
DeleteAce()
GetFileSecurity()
....

-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top