简体   繁体   English

如何区分Winapi中的Volume和File句柄?

[英]How to differentiate between Volume and File handle in winapi?

I am iterating over all the handles opened by my process after making sure that I have opened up a volume handle. 在确保已打开卷句柄之后,我将遍历由进程打开的所有句柄。 During iteration, I use GetFinalPathNameByHandle() to receive information about object associated with the certain handle but as I see it this function only works with files and returns ERROR_INVALID_HANDLE (0x06) error in case of handles other than files. 在迭代过程中,我使用GetFinalPathNameByHandle()来接收有关与特定句柄关联的对象的信息,但是正如我看到的那样,此函数仅适用于文件,并且在文件句柄以外的情况下返回ERROR_INVALID_HANDLE(0x06)错误。 Am I right on this? 我说得对吗? If yes, then how can I check whether the handle in question is associated with volume so that I can close it? 如果是,那么我该如何检查相关的手柄是否与音量相关联,以便我可以将其关闭?

Any help woudl be appreciated. 任何帮助将不胜感激。

You are doing this all wrong. 您做错了所有。 When you create a handle, remember it. 创建手柄时,请记住它。 When you are done with it, close it. 完成后,将其关闭。

You cannot hope to be able to enumerate all open handles in your process and close a bunch of them that meet some criteria. 您不能希望能够枚举过程中所有打开的句柄并关闭其中一些符合某些条件的句柄。 You have no way of knowing whether or not the handle is in use. 您无法知道手柄是否在使用中。 There will be handles open in your process that were not opened by your code. 将在您的过程中打开未被代码打开的句柄。 Closing such handles will lead to all sorts of pain. 关闭此类手柄将导致各种痛苦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM