Is there a way to detect deletion of a file before windows performs the deletion? I found FileSystemWatcher class but the event is raised only after the delete action is performed but I want to trap the delete action once the user/process chooses to delete it. You can monitor the file system table but looking for a better approach. Thanks for your help.
Share
I think the simpliest way is to use a hook to get notified (and eventually to stop) the process. It can’t be done in .NET so you have to
DllImporta lot of structures and few functions to P/Invoke.Let’s start your job with the
NtSetFileInformation(undocumented) function. It’s the function called by anything else when a file need to be deleted (with theFileDispositionInformationstructure).Now the problem is how to hook that function (good luck, it’s not easy). A good choice can be to use Microsoft Detours. Take a look to this article for an example. Its problem is that it’s not free. An alternative solution (with a reasonable price and with a .NET interface) is Deviare but I never tried even their free version so I don’t know how much it’s good. If someone else knows a good interception tool…