Windows:如何获得已打开文件的模式/访问权限? [英] Windows: How do I get the mode/access rights of an already opened file?
问题描述
我正在编写一个使用数据库库的程序.该库使我可以访问它用于访问我的表的文件句柄.我找到了一个 Windows API,它允许我通过句柄检索有关文件的信息,但我还没有找到任何方法来确定该文件的访问模式/权限.在这一点上,我确信我可能会在不知道这些信息的情况下生活,但作为一个顽固的诅咒我还没有准备好放过这个.显然 Windows 知道这些信息——所以问题是如何从它那里哄骗信息?
I am writing a program that is using a database library. The library provides me access to the file handle it uses to access my table. I've found a windows API that allows me to retrieve information about the file by handle but I've yet to find any means of determining access mode / permissions of that file. At this point I'm sure I could likely live without knowing this information but being the stubborn cuss that I am I'm not ready to let this one go. Obviously Windows knows this info - so the question is how can coax the info out of it?
我发现的 API 函数是:GetFileInformationByHandleEx,它让我靠近水坑,但不让我喝水.
The API function that I've found is: GetFileInformationByHandleEx and it takes me close to the watering hole but doesn't let me drink the water.
文件模式信息有用的原因是我需要修改表头信息.如果文件已经处于正确的模式,那么我就不必关闭表打开文件修改文件关闭文件然后重新打开表.
The reason that the file mode information is useful is that I need to modify the table header information. If the file is already in a proper mode then I won't have to close the table open the file modify the file close the file then re-open the table.
是的,在我被告知可以实现我的目标的所有选项之前 - 我对这些不感兴趣.我只对原始问题感兴趣 - 如何确定已打开文件的模式.我期待着任何回复,并提前感谢您.
And yes, before I'm told of all the options available to me to achieve my goal - I'm not interested in those. I'm only interesting in the original question - how do I determine the mode of an already opened file. I look forward to any responses and I thank you in advance.
谢谢,罗伯特·米利根
推荐答案
我不知道是否有相应的 Win32 API,但如果你真的需要它,你可以调用 NtQueryObject(ObjectBasicInformation).
I don't know if there is a corresponding Win32 API for this, but if you really need it you can call NtQueryObject(ObjectBasicInformation).
这篇关于Windows:如何获得已打开文件的模式/访问权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!