问题
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