1

I want to create a file and give a user write permission.

IO.File.Create(Path & "\test.json")
Dim fs As Security.AccessControl.FileSecurity = IO.File.GetAccessControl(Path & "\test.json")
Dim far As Security.AccessControl.FileSystemAccessRule = New Security.AccessControl.FileSystemAccessRule("DOMAIN\USER", Security.AccessControl.FileSystemRights.WriteData, Security.AccessControl.AccessControlType.Allow)
fs.AddAccessRule(far)

When I check the Security tab for this file, I see no changes. VS2015 output window does not show any exceptions. VS2015 is running as Administrator.

I used this for reference: https://msdn.microsoft.com/en-us/library/d49cww7f(v=vs.110).aspx

Tyler Montney
  • 1,402
  • 1
  • 17
  • 25

1 Answers1

1

All you have changed in your code is the in-memory file security. In order to apply these changes to the file, you must call SetAccessControl.

For example:

File.SetAccessControl(Path & "\test.json", fs)
competent_tech
  • 44,465
  • 11
  • 90
  • 113