
Originally Posted by
Dushidude
His code will grant the user modify access. How can I edit the code to my desires? And what does he mean with "MYDOMAIN\someuser"?
I modified like this to deny access to the specified file
VB.NET Code:
Option Strict On
Option Explicit On
Imports System.Security.AccessControl
Public Class Form1
Dim FilePath As String = "file\path" 'Specify the file here
Dim UserAccount As String = "computer_name\user_name" 'Specify the user here
Dim FileInfo As IO.FileInfo = New IO.FileInfo(FilePath)
Dim FileAcl As New FileSecurity
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
FileAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.Modify, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Deny))
'FileAcl.SetAccessRuleProtection(True, False) 'uncomment to remove existing permissions
FileInfo.SetAccessControl(FileAcl)
End Sub
End Class
Edit:
to know your computer name, open Control Panel> System> and see Computer name