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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Security permission of file 1

Status
Not open for further replies.

eelisdotnet

Programmer
Oct 3, 2004
10
FI
Hi

I'm trying to check a file for its security permissions to determine if it is writeable or not.
The code looks like that:

Function IsFileWritePermission(ByVal sFileName As String) As Boolean
Try
Dim fp As FileIOPermission
fp = New FileIOPermission(FileIOPermissionAccess.Write, sFileName)

fp.Demand()

Return True
Catch ex As Security.SecurityException
Return False
Catch ex As Exception
Return False
End Try
End Function




The file i'm testing has a Deny Write permission but the function always return true. If I try to open the file to write, it raises an error exception for write permission.

Thanks.
 
I flipped through the documentation on FileIOPermission, it looks like it's only designed to set permissions. So in this case it is likely setting the permission to write access, then returning true.

If you just need local file attributes, you can get them with:
Code:
Dim fa As FileAttribute
fa = System.IO.File.GetAttributes("c:\test.txt")
Debug.Write(fa.ToString)

I'm still looking for code to grab the windows/AD permissions though.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top