首页 > 解决方案 > 从基于 Is64Bit bool 的路径中获取 FileInfo

问题描述

所以我有一个string Path代表文件路径的文件,C:\Windows\System32\cmd.exe例如。

我的应用程序设置为 Any CPU 并且不会改变,但是给定一个bool Is64Bit标志,我怎样才能有一个返回以下内容的方法:

// On 64 bit OS
GetFileInfo("C:\\Windows\\System32\\cmd.exe", Is64Bit: true); // return C:\Windows\System32\cmd.exe
GetFileInfo("C:\\Windows\\System32\\cmd.exe", false); // return C:\Windows\Syswow64\cmd.exe
GetFileInfo("C:\\Program Files\\file.txt", true); // return C:\Program Files\file.txt
GetFileInfo("C:\\Program Files\\file.txt", false); // return C:\Program Files (x86)\file.txt
// On 32 bit OS
GetFileInfo("C:\\Windows\\System32\\cmd.exe", true); // return C:\Windows\System32\cmd.exe
GetFileInfo("C:\\Windows\\System32\\cmd.exe", false); // return C:\Windows\System32\cmd.exe
GetFileInfo("C:\\Program Files\\file.txt", true); // return C:\Program Files\file.txt
GetFileInfo("C:\\Program Files\\file.txt", false); // return C:\Program Files\file.txt

换句话说,有没有办法强制将路径从 64 位应用程序重定向到其 32 位对应项?

标签: c#.netwindows

解决方案


推荐阅读