如何找到&关闭可移动驱动器上所有打开的文件句柄(弹出之前)
我正在尝试弹出(虚拟)可移动驱动器,但它失败了,因为有一些文件句柄打开,可能是资源管理器窗口。获取该驱动器上文件的所有打开句柄并关闭它们的最佳方法是什么?
是否也可以(在用户模式下)找到从该驱动器运行的任何进程,以便我可以用进程名称警告用户?
理想情况下,我想在用户模式应用程序中执行此操作,而不需要管理员权限。
我在 Visual Studio 2005 的 MFC 应用程序中使用 VC++,但欢迎提供任何语言的示例!
I'm trying to eject a (virtual) removable drive, and it fails because there are some file handles open, maybe explorer windows. What's the best way to get all the open handles to files on that drive and close them?
Is it also feasible (within user-mode) to find any processes running off that drive, so I can warn the user with the process name?
Ideally I'd like to do this within a user-mode app rather than require admin privileges.
I'm using VC++ in Visual Studio 2005, in an MFC app, but samples in any language would be welcome!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Process Explorer 实用程序可以搜索打开的句柄,但我不这样做不知道在没有提升权限的情况下是否可以这样做。据我所知,它使用“性能计数器”API 来完成此操作。
我认为本文满足您的需要,枚举正在运行的进程,枚举每个进程的句柄,查找引用相关驱动器上路径的文件句柄:
如何枚举进程的句柄?
The Process Explorer utility can search for open handles, but I don't know whether it can do so without elevated privileges. From what I've been able to gather, it does this using the "Performance Counters" API.
I think this article does what you need, enumerate the running processes, enumerate the handles for each one, look for a file handle referencing a path on the drive in question:
How to enumerate process' handles?