如何获取重定向路径的实际路径? [英] How to get Actual path of redirected path?

查看:37
本文介绍了如何获取重定向路径的实际路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于文件重定向,在 64 位上运行的 32 位进程将获得通用重定向路径的路径.例如,如果进程从 WindowsSysWOW64 运行,则调用 GetCurrentDirectory 会得到结果:WindowsSystem32.

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 WindowsSysWOW64 would get result: WindowsSystem32.

不过,很有可能确定 32 位进程是否在 64 位主机上运行.我正在寻找一种解决方案来为我提供正确/实际的路径.类似于 ResolveWOWPathToActual 路径,它会给 WindowsSysWOW64 一个路径 WindowsSystem32.

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 WindowsSysWOW64 for a path WindowsSystem32.

WCHAR szCurFolder[MAX_PATH];

PVOID dummy;
Wow64DisableWow64FsRedirection(&dummy);

GetCurrentDirectoryW(MAX_PATH, szCurFolder);

printf("Current Dir: %S
", 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆