如何获取重定向路径的实际路径? [英] How to get Actual path of redirected path?
问题描述
由于文件重定向,在64位上运行的32位进程将获得到重定向路径的广义路径。例如,如果进程正在从 \Windows \SysWOW64
运行,则会调用 GetCurrentDirectory
code> Windows\System32 。
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
.
但是,很有可能确定32位进程是否正在64位主机上运行。我正在寻找一个解决方案给我正确/实际的路径。像ResolveWOWPathToActual路径,这将给 \Windows \SysWOW64
路径 \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
.
编辑:
WCHAR szCurFolder[MAX_PATH];
PVOID dummy;
Wow64DisableWow64FsRedirection(&dummy);
GetCurrentDirectoryW(MAX_PATH, szCurFolder);
printf("Current Dir: %S\n", szCurFolder);
推荐答案
API函数 GetFinalPathNameByHandle
可能满足您的需求。您将必须打开文件或目录来获取它的句柄。将该句柄传递到 GetFinalPathNameByHandle
,它将为您提供文件的真实路径。没有必要禁用文件系统重定向程序。
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.
这篇关于如何获取重定向路径的实际路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!