Windows:如何获取已打开文件的模式/访问权限? [英] Windows: How do I get the mode/access rights of an already opened file?

查看:111
本文介绍了Windows:如何获取已打开文件的模式/访问权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用数据库库的程序.该库使我可以访问用于访问表的文件句柄.我找到了一个Windows API,该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.

谢谢, 罗伯特·米利根(Robert Milligan)

Thanks, Robert Milligan

推荐答案

我不知道是否有相应的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屋!

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