|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Checking Folder Access PermissionsI am working on a File Manager app and would like to know the permissions
on a folder before I attempt to open it in the app. I have been going through the help and Google this afternoon but am feeling a bit confused. Is there a way that I can check whether I/the user has access to a folder before attempting to open/enter it? Many thanks. -- Jeff Gaines Hi Jeff,
Thanks for your post! Based on my understanding, your File Manager application wanted to manage and check certain user's NTFS access to a folder in .Net. In Windows security world, all the objects are protected with DACL in Security Descriptor. The DACL contains a list of ACEs, which describes which account can/can't access this object. So is the Folder object. The Windows DACL security feature is not supported in .Net1.1, but is partial added in .Net2.0. To dump out the DACL of a folder, you may use Directory.GetAccessControl method to get the DirectorySecurity class, and then loop through the result set from DirectorySecurity.GetAccessRules to dump each ACE content. The figure3 in the article below provides some sample regarding dumping DACL of a file, which is easy to modified into folder: "Manage Access to Windows Objects with ACLs and the .NET Framework" http://msdn.microsoft.com/msdnmag/issues/04/11/AccessControlinNET/ To programmatically access check if a user has certain access right to a folder, Windows provides AccessCheck API for this purpose. However, based on my research, I found .Net2.0 did not provide support for this API, so you have to p/invoke this win32 API to achieve what you want. Actually, in .Net world, the simplest way of access checking is performing the folder accessing directly and catch the access deny exception to indicate the failure, or the accessing is granted. AccessCheck API is a somewhat complex API, if you want to p/invoke to it, please refer to the article below for more information: "The Windows Access Control Model Part 3" http://www.codeproject.com/csharp/accessctrl3.asp Finally, the article below provides a rude way of doing access checking in .Net. That is he simulate the work of AccessCheck API in .Net by checking each ACE for grant/deny information, if you do not like the complexibility of p/invoke AccessCheck and throw exception with direct access, this is another choice for you: "Testing file access rights in .NET 2.0" http://www.codeproject.com/useritems/UserFileAccessRights.asp Hope this helps. If you need further help or other concern, please feel free to tell me, thanks! Best regards, Jeffrey Tan Microsoft Online Community Support ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. On 17/07/2006 "Jeffrey Tan[MSFT]" wrote: Jeffrey>Finally, the article below provides a rude way of doing access checking in >.Net. That is he simulate the work of AccessCheck API in .Net by checking >each ACE for grant/deny information, if you do not like the complexibility >of p/invoke AccessCheck and throw exception with direct access, this is >another choice for you: >"Testing file access rights in .NET 2.0" >http://www.codeproject.com/useritems/UserFileAccessRights.asp > >Hope this helps. It certainly does, thank you very much :-) I went for the above CodeProject solution, I must tune up my search skills though - I had tried CodeProjet, GotDotNet and MSDN without success:-( -- Jeff Gaines Hi Jeff,
I am glad my reply can help you. The search keyword for this article is not easy to determine, I finally use "GetAccessControl" in google to find this article :-). If you need further help, please feel free to post, we will help you in the newsgroup. Thanks. Best regards, Jeffrey Tan Microsoft Online Community Support ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
|||||||||||||||||||||||