How to get Actual path of redirected path?

戏子无情 提交于 2019-12-11 04:11:54

问题


A 32-bit process running on 64-bit would get generalized path to a redirected path, due to file-redirection. A call to GetCurrentDirectory, for example, if process is running from \Windows\SysWOW64 would get result: Windows\System32.

Though, it is very much possible to determine if 32-bit process is running on 64-bit host machine. I am looking for a solution to give me correct/actual path. Something like ResolveWOWPathToActual path, that would give \Windows\SysWOW64 for a path \Windows\System32.

EDIT:

WCHAR szCurFolder[MAX_PATH];

PVOID dummy;
Wow64DisableWow64FsRedirection(&dummy);

GetCurrentDirectoryW(MAX_PATH, szCurFolder);

printf("Current Dir: %S\n", szCurFolder);

回答1:


The API function GetFinalPathNameByHandle might serve your needs. You will have to open the file or directory to obtain a handle to it. Pass that handle to GetFinalPathNameByHandle and it will give you the true path of the file. There is no need to disable the file system redirector.

I suppose the only possible downside is that this does require you to supply a handle rather than a path.



来源:https://stackoverflow.com/questions/23650436/how-to-get-actual-path-of-redirected-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!