Checking folder rights on the server
I would like to programmatically (vb.net) check a folder rights on a server. I want to check a user logon to a server has
the Write permission on that folder. Specifically i want to check the "Temporary ASP.NET Files" folder. I've used impersonation and then use System.Security.Permissions.FileIOPermission() to check, but it doesn't work.
I always get folderRight = "Y". The user that is logged on to the server is member of [domain]/users, and i have removed
the "Write" permission for [domain]/users for that folder.
Anyone can help to solve this issue? Thanks.
Edit: Our company has a website, the web site is in the server, below codes are in an aspx
page, when a user (from client PC) log in to the server, the server will access the aspx page and execute below codes.
Below is my code:
Dim impersonationContext As System.Security.Principal.WindowsImpersonationContext
impersonationContext = CType(Context.User.Identity,System.Security.Principal.WindowsIdentity).Impersonate()
Dim tempPath As String = System.Environment.GetEnvironmentVariable("windir") & "\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files"
Try
Dim f As New System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Write, tempPath)
f.Demand()
folderRight = "Y"
Catch ex As Exception
folderRight = "N"
End Try
impersonationContext.Undo()
December 6th, 2010 4:12am
Hi,
Generally, we can use the CACLS.EXE to check the folder permissions. For more information, please refer to the following articles:
How to Use CACLS.EXE in a Batch File
http://support.microsoft.com/kb/135268
Cacls
http://technet.microsoft.com/en-us/library/bb490872.aspx?wa=wsignin1.0
Considering that you would like to achieve this goal via coding, MSDN forum is the best resource for you. I would like to suggest you submit a new question
to MSDN forum for further assistance.
Microsoft Developer Network
http://social.msdn.microsoft.com/Forums/en/categories/
Regards,Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
December 8th, 2010 10:30pm