Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

GetFinalPathNameByHandle API Hangs

, 8 Apr 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
GetFinalPathNameByHandle is an new API introduced in Windows Vista. We will look at how to resolve an issue related to its usage.

GetFinalPathNameByHandle is a new API introduced in Windows Vista. As you can read from MSDN, the purpose of this API is to return the file name corresponding to a file handle.

Some months back, I wrote a small utility, OpenedFileFinder, which lists all the files that are opened under a certain folder. While writing this application, the main problem I came across was to get the file name from the handle. Initially, I used a function called NtQueryObject(). But the problem with this API is that if we try to query the details for a certain object such as a pipe, directory handle etc., it will hang. So, in my application, I introduced a driver to get around this hanging problem. When I found the new GetFinalPathNameByHandle(), I was so happy and I thought at least I could avoid the driver in Vista. I tried the API, but came to find that this API also has the same problem described earlier.

It seems the GetFinalPathNameByHandle also uses the same NtQueryObject() to get the file name and so it hangs. Any how, I reported this bug to Microsoft Connect. Let us see how they solve the problem.

Another API that is worth mentioning here is GetFileInformationByHandleEx(), which is also a new API introduced in Vista. Using this API, I can get the file name from a handle. So I decided to check whether the same problem exists in this API. Surprisingly, it worked fine. And in MSDN, it is mentioned that it uses a driver for attaining the task. So I highly recommend using the GetFileInformationByHandleEx() API instead of GetFinalPathNameByHandle().

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Naveen
Software Developer (Senior)
Singapore Singapore
No Biography provided

Comments and Discussions

 
AnswerVery poor [modified] PinmemberElmue11-Sep-13 6:29 
GeneralRe: Very poor PinmemberNaveen30-Oct-13 0:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411023.1 | Last Updated 8 Apr 2009
Article Copyright 2009 by Naveen
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid