How to intercept the access to a file in a .NET Program

后端 未结 5 1079
梦如初夏
梦如初夏 2021-02-20 05:37

I need to intercept when the system tries to access to a file, and do something before it happens.

5条回答
  •  一向
    一向 (楼主)
    2021-02-20 06:05

    Interesting question. What kind of access? Read, write, delete, copy?

    • If you need to prevent access to a file then the security would be the way. Then you can capture the access and do delegate the task to a higher privileged execution engine. Such as a service running as higher privileged user.

    • If you want to stop system level access then you'll need an IFS filter.

    • If all access is via your code, then I'd suggest a library that prevent's access.

    • And as other people have mentioned, there is the FileSystemWatcher, but I think this post access not before.

提交回复
热议问题