如何检查在应用程序外部打开的文件? [英] How can I check for files opened externally to my application ?

查看:92
本文介绍了如何检查在应用程序外部打开的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查某些文件是否已在我的应用程序外部打开,即通过在Windows资源管理器中单击文件,然后在诸如记事本之类的应用程序中打开该文件.但是我找不到解决办法.

我已经使用modeWrite和CFile :: Write()尝试了CFile :: Open(),并且如果在其他地方打开了文件,这些也不会失败.

还有另一种方法吗?

I need to check if certain files have been opened externally to my application i.e by clicking on the file in windows explorer, and then the file opens in an application like notepad. But I can''t to find a way to do this.

I have tried CFile::Open() with modeWrite, and CFile::Write(), and these do not fail if the file has been opened elsewhere.

Is there another way?

推荐答案

您的方法基本上是正确的,应该可以工作,但是它是破坏性的,您可能想使用read代替或检查流大小.问题在于可以打开文件以进行非独占访问,这不是很典型,但是您的检测方法无法检测到它.

您可以尝试以下操作: http://read.pudn.com/downloads36 /sourcecode/windows/111597/NtSystemInfo/NtSystemInfoTest/NtSystemInfoTest.cpp__.htm [ http://technet.microsoft.com/zh-cn/sysinternals/bb842062 [ ^ ].

—SA
Your method is basically correct and should work, but it is destructive, you may want to use read instead or check stream size. The problem is that the file could be opened for non-exclusive access, which is not very typical but your method of detection won''t detect it.

You can try this: http://read.pudn.com/downloads36/sourcecode/windows/111597/NtSystemInfo/NtSystemInfoTest/NtSystemInfoTest.cpp__.htm[^].

Also, it may happen that you think the file is opened but actually it is not. Please check it up. For example, many text editor do not keep a file handle open. They open a file, read it all into the application''s memory and close immediately. File is read and not opened. You can check up what really happens using Sysinternals Process Explorer: see Sysinternals Suite: http://technet.microsoft.com/en-us/sysinternals/bb842062[^].

—SA


这篇关于如何检查在应用程序外部打开的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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