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!
Re: Make file not moveable, copyable or deleteable?
Re: Make file not moveable, copyable or deleteable?
Re: Make file not moveable, copyable or deleteable?
I really struggle with this. Tried all day. :/
Re: Make file not moveable, copyable or deleteable?
Quote:
Originally Posted by
patel45
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 :)
Re: Make file not moveable, copyable or deleteable?
See this, it is VB.NET code but it is not difficult to convert to C#
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"?
Re: Make file not moveable, copyable or deleteable?
Quote:
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