|
-
Aug 15th, 2017, 01:20 PM
#1
Thread Starter
Junior Member
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!
-
Aug 15th, 2017, 02:09 PM
#2
Addicted Member
Re: Make file not moveable, copyable or deleteable?
-
Aug 15th, 2017, 02:09 PM
#3
Re: Make file not moveable, copyable or deleteable?
-
Aug 15th, 2017, 02:30 PM
#4
Thread Starter
Junior Member
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.
-
Aug 15th, 2017, 02:32 PM
#5
Thread Starter
Junior Member
Re: Make file not moveable, copyable or deleteable?
-
Aug 15th, 2017, 02:37 PM
#6
Re: Make file not moveable, copyable or deleteable?
See this, it is VB.NET code but it is not difficult to convert to C#
-
Aug 15th, 2017, 02:39 PM
#7
Thread Starter
Junior Member
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"?
-
Aug 15th, 2017, 03:14 PM
#8
Re: Make file not moveable, copyable or deleteable?
 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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|