枚举文件在C#拉手 [英] Enumerating File Handles in C#

查看:121
本文介绍了枚举文件在C#拉手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能枚举文件句柄在C#中,也许使用Win32API的。这是很容易的窗口和进程处理完成,但它似乎是不可能的文件句柄。

I would like to know whether it is possible to enumerate file handles in c#, maybe using Win32API. This is easily done for window and process handles, but it seems that it is not possible for file handles.

虽然有些功能是通过NtQuerySystemInformation提供,这是被淘汰因此不建议使用这种方法。

While some functionality is offered by NtQuerySystemInformation, this is being phased out and therefore it is not recommended to use such a method.

推荐答案

好了,你知道这是可能的,Sysinternals的手柄效用呢它。 NtQueryInformation是不会被淘汰,这是Win32和真正的操作系统之间的重要低级接口。

Well, you know it is possible, SysInternals' Handle utility does it. NtQueryInformation isn't going to be phased out, it is an essential low-level interface between Win32 and the "real" operating system.

什么是但永远也不会发生是该允许迭代手柄NtQueryInformation参数将被记录在案。因为它不只是停在那里,一些布偶会用它来上是个文件调用CloseHandle的()/他不希望被锁定。这是一个的非常的良好摧毁你的硬盘中的内容的方式。

What is however never going to happen is that the NtQueryInformation arguments that allow iterating handles is going to be documented. Because it doesn't stop just there, some muppet is going to use it to call CloseHandle() on a file that s/he doesn't want to be locked. Which is a very good way to destroy your hard disk content.

这所拥有的手柄不知道把手的过程中被关闭。它只会继续写下去,很可能完全无视来自WriteFile的了没有工作返回代码()。这是无害的,直到程序打开另一个手柄,得到了相同的值回作为先前关闭的。现在开始写垃圾的混合物(用于前一手柄)和新的数据到手柄。彻底摧毁不管它是写的内容。自旋向上的备份磁带,如果这有点像一个关键任务数据库。

The process that owned the handle doesn't know the handle is closed. It will just keep writing to it, probably completely ignoring the "it didn't work" return code from WriteFile(). Which is harmless until the program opens another handle, getting the same value back as the one that was closed earlier. Now it starts writing a mix of garbage (intended for the previous handle) and new data to the handle. Utterly destroying the content of whatever it is writing to. Spin up the backup tapes if that's something like a mission critical database.

这篇关于枚举文件在C#拉手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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