Search code examples
c#filesystemwatcher

How to prevent copy, paste and delete file from the determined directory


I'm doing some task in my team's project. I did my first work that is how to recognize and get file from the USB which contains a register file. And I have researched how to prevent some action like: copy, paste, delete files from the USB which don't contain a register file. Until now, I don't have any idea to solve this problem.

If there are unauthorized USB and authorized USB in my computer. I can copy, paste, delete files from authorized USB but unauthorized USB.

I have tried using FileSystemWatcher but I just can handle "file changed" info AFTER it's changed. How can I handler BEFORE it's changed (before it 's done copy, paste or delete) ?

I thought something work as Prevent v1.0 program, but not prevent all the files, just from the determined directory and I don't have source code of Prevent v1.0

Any help will be precious.


Solution

  • You need to use a file system filter driver in order to deny writing or deletion. You can write your own (6-9 man-months of work to get it right), or you can use our CallbackFilter product, which lets you complete your task in about an hour.

    Remember, that the OS doesn't have "file copy" operation. File copying is a sequence of file open/file read/file write/file close operations.