Click here to Skip to main content
15,608,738 members
Articles / Programming Languages / C#
Technical Blog
Posted 8 Apr 2009

Tagged as


6 bookmarked

GetFinalPathNameByHandle API Hangs

Rate me:
Please Sign up or sign in to vote.
3.86/5 (3 votes)
8 Apr 2009CPOL1 min read
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().

This article was originally posted at


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

Written By
Software Developer (Senior)
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

Questionpipes Pin
pionko28-Apr-19 10:22
pionko28-Apr-19 10:22 
GetFinalPathNameByHandle may hang on pipes, to avoid hang make sure that duplicated handle is not a pipe
if(GetFileType(pHandle) != FILE_TYPE_PIPE)

AnswerVery poor Pin
Elmue11-Sep-13 5:29
Elmue11-Sep-13 5:29 
GeneralRe: Very poor Pin
Naveen29-Oct-13 23:39
Naveen29-Oct-13 23:39 

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

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