1

I'm wondering if there is a way for a process to "lock" a complete folder/directory and not allow any other process (except its child process created using Process.Start) to modify/delete anything in there. I don't mind allow read-only access, but that's not a requirement.

The idea is that MyProcess should be able to acquire a lock on a DIRECTORY (not a file) and not allow any other process to modify the contents of that directory. It is a requirement however that the INHERITED PROCESS (started using Process.Start() from MyProcess) should be able to modify that directory, but no one else.

I'm using C# (Windows environment).

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
UserXYZ
  • 223
  • 3
  • 13
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Jan 31 '14 at 02:27
  • 1
    You can monkey with Directory.SetAccessControl(). That doesn't have anything to do with a "lock". And always ends quite poorly when the program bombs. So, no. Renaming or moving the directory so that other programs are incapable of guessing what the new name looks like is a simple trick. Silly enough to see that the approach is way too flawed. – Hans Passant Jan 31 '14 at 02:39
  • Possible duplicate: http://stackoverflow.com/questions/1433964/can-we-lock-a-directory – Onots Jan 31 '14 at 02:47
  • Why would you want to do this in the first place? – Sam Axe Jan 31 '14 at 04:16
  • Because I need to ensure that no other application messes with the directory while ProcessX is working on it. – UserXYZ Jan 31 '14 at 05:50
  • Consider checking this question and the proposed answer: http://stackoverflow.com/questions/32234682/c-sharp-locking-folders-from-being-edited/32235681#32235681 – halsten Aug 26 '15 at 22:28

1 Answers1

1

The simple answer is: No. This is not a scenario supported by the operating system.

Sam Axe
  • 33,313
  • 9
  • 55
  • 89