How to get name associated with open HANDLE

后端 未结 7 571
终归单人心
终归单人心 2020-11-27 06:13

What\'s the easiest way to get the filename associated with an open HANDLE in Win32?

7条回答
  •  抹茶落季
    2020-11-27 06:45

    For Windows Vista and later I prefer to use GetFinalPathNameByHandle()

    char buf[MAX_PATH];
    GetFinalPathNameByHandleA(fileHandle, buf, sizeof(buf), VOLUME_NAME_DOS)
    

    For Windows XP I prefer the solution by Mehrdad.

    So I load GetFinalPathNameByHandle() dynamically via GetProcAddress() and if this fails (because it's Windows XP) I go for Mehrdad's solution with NtQueryObject()

提交回复
热议问题