Results 1 to 8 of 8

Thread: Make file not moveable, copyable or deleteable?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2017
    Posts
    18

    Make file not moveable, copyable or deleteable?

    I am here from CodeProject, but they don't seem to have an answer to my question. I just want a desktop file to have security permission(make the file not moveable, copyable or deletable). This is possible to do manually in the file's "properties". I am using C#, your help is much appreciated - thanks!

  2. #2
    Addicted Member
    Join Date
    May 2017
    Location
    Italy
    Posts
    170

  3. #3
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: Make file not moveable, copyable or deleteable?

    https://msdn.microsoft.com/en-us/lib...or=-2147217396 should get you started.

    Patel45 beat me to it.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2017
    Posts
    18

    Re: Make file not moveable, copyable or deleteable?

    I really struggle with this. Tried all day. :/
    Last edited by Dushidude; Aug 15th, 2017 at 02:34 PM.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2017
    Posts
    18

    Re: Make file not moveable, copyable or deleteable?

    Hello man, I struggle to understand and get it to work You gave me some good links, but can you give me an example with source code on what the code should look like if I want to make my file not moveable, copyable or deleteable? Thanks man

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

    Re: Make file not moveable, copyable or deleteable?

    See this, it is VB.NET code but it is not difficult to convert to C#



  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2017
    Posts
    18

    Re: Make file not moveable, copyable or deleteable?

    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"?

  8. #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