Question Reading NTFS permissions for a file

exaray

New member
Joined
Mar 9, 2009
Messages
2
Programming Experience
3-5
I want to read the NTFS permissions belonging to a certain file (which user has which rights).

e.g.:
If <user xy has read access to file abc.txt> Then
do something
End If

I know how to check if the actually logged in user (in whose context the program runs) has access rights to a file, it's important for me to see the whole ACL (which OTHER users have which rights).

I hope someone can give me an example code...
 
hi
i think the easiest way for checking & preventing of some file access exceptions is to put your code into a Try Catch block,

VB.NET:
Imports System
Imports System.IO
Class Program
    Private Shared Sub Main()
        
        
        Try
            
            
            Dim mahi2 As New FileStream("C:\YServer.txt", FileMode.Open)
            
            Console.Write(mahi2.CanRead.ToString())
            Console.Write(mahi2.CanWrite.ToString())
            
            
        Catch e As Exception
            Console.WriteLine(e.Message)
        End Try
        Console.ReadLine()
    End Sub
End Class
if you want some more advanced topics about NTFS file permissions - add some rules - remove some rules & so on google these namespaces :
Imports System.Security.AccessControl
Imports System.Security.Permissions
have a nice day
 
Back
Top