删除文件时会发送什么Windows消息? [英] What Windows Message is sent when deleting a file?

查看:186
本文介绍了删除文件时会发送什么Windows消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算编写一个应用程序来检测文件是否即将被删除(例如,通过右键单击文件并选择删除"或通过代码).

该要求使我想到了 Global Hook ,我想知道的是将要删除文件时发送的 windows消息,应避免此消息在执行 delete 命令之前.

你能告诉我这是什么吗?如果可能的话,请给我另一个解决方案(更轻松)来帮助我构建这样的应用程序!

非常感谢!

I intend to write an application to detect if a file is about to be deleted ( Such as by right-clicking on the file and select "Delete" or by code).

That requirement makes me think of Global Hook and what I want to know is the windows message that will be sent when a file is about to be deleted, this message should be prevented before the delete command is executed.

Could you please tell me what it is? If possible, Please give me another solution (easier to do) to help me build such an application!

Thank you so much!

推荐答案

我不认为您可以在托管代码中甚至通过FileSystemWatcher来实现此目标,如果您想在实际删除发生之前就收到删除通知.

您可能需要看看 [
I do not think you can achieve this in managed code or even via FileSystemWatcher if you want a notification of delete before actual delete happens.

You may have to take a look at this[^] to achieve something similar.

Note: I don''t know how to do this. I just stumbled upon it while googling.


我必须问一下您要防止删除的文件以及为什么.

如果您在谈论应用程序数据文件,那么,如果用户足够愚蠢以删除数据文件,那么他应该愿意承受这样做的后果.

您始终可以将文件的备份存储在一个隐藏的文件夹中,如果您打开该文件后发现该文件不存在,则可以从上次进行的备份中还原该文件.
I have to ask what file you''re trying to prevent from being deleted and why.

If you''re talking about application data files, well, if the user is stupid enough to delete a data file, he should be willing to live with the ramifications of doing so.

You could always store a backup o the file in a hidden folder, and if you go to open that file and discover that it doesn''t exist, you can restore it from the last backup that was made.


没有这样的窗口消息!但是您可以有这样的.NET事件.要触发和处理此类事件,请使用类System.IO.FileSystemWatcher,请参见 http://msdn .microsoft.com/en-us/library/system.io.filesystemwatcher.aspx [ http://msdn.microsoft.com/en-us/library/6e3b887c(VS .71).aspx [ ^ ].

—SA
There is no such Window message! But you can have such .NET event. To trigger and handle such events, use the class System.IO.FileSystemWatcher, see http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx[^].


It won''t help to prevent deletion though. One way to prevent deletion is having some process (it can be your application) which keeps all files you need open without shared access (which is the default). This is simple: don''t close the streams you''re working with before you exit your application. As to executable files, they are already protected if they are loaded.

Number of simultaneously open file handles is limited. The situation is described here:
http://msdn.microsoft.com/en-us/library/6e3b887c(VS.71).aspx[^].

—SA


这篇关于删除文件时会发送什么Windows消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆