Results 1 to 8 of 8

Thread: Make file not moveable, copyable or deleteable?

Threaded View

  1. #8
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Make file not moveable, copyable or deleteable?

    Quote Originally Posted by Dushidude View Post
    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:
    1. Option Strict On
    2. Option Explicit On
    3.  
    4. Imports System.Security.AccessControl
    5.  
    6. Public Class Form1
    7.  
    8.     Dim FilePath As String = "file\path" 'Specify the file here
    9.     Dim UserAccount As String = "computer_name\user_name" 'Specify the user here
    10.  
    11.     Dim FileInfo As IO.FileInfo = New IO.FileInfo(FilePath)
    12.     Dim FileAcl As New FileSecurity
    13.  
    14.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    15.         FileAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.Modify, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Deny))
    16.         'FileAcl.SetAccessRuleProtection(True, False) 'uncomment to remove existing permissions
    17.         FileInfo.SetAccessControl(FileAcl)
    18.     End Sub
    19.  
    20. End Class

    Edit:
    to know your computer name, open Control Panel> System> and see Computer name
    Last edited by 4x2y; Aug 15th, 2017 at 03:19 PM.



Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width