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

房东的猫 提交于 2019-12-11 22:06:15

问题


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.


回答1:


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.




回答2:


Untested, but ... how about setting the file attributes to read-only and then, once this changes, revert the change by enabling write protection again?

What are you trying to do? Implementing some kind of hardware dongle? In that case I'd just try to get as much USB drive information as possible into your file to check against the drive's actual data (serial number, vendor id, etc.). Cause other "unmodified" PCs would still be able to change the drive, even while using some kind of file system filter.



来源:https://stackoverflow.com/questions/5231265/how-to-prevent-copy-paste-and-delete-file-from-the-determined-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!