在 64 位 Windows 上,32 位進程訪問 C:\Windows\System32 會被自動重定向到 C:\Windows\SysWOW64;而 64 位進程訪問 System32 看到的是真正的 64 位系統文件。這是為了兼容 32 位應用程式而設計的文件系統重定向器。
| 進程位數 | 訪問路徑 | 實際訪問路徑 | 說明 |
|---|---|---|---|
| 32 位 | C:\Windows\System32 | C:\Windows\SysWOW64 | 存放 32 位 DLL/EXE |
| 32 位 | C:\Windows\Sysnative | C:\Windows\System32 | 虛擬別名,繞過重定向 |
| 64 位 | C:\Windows\System32 | C:\Windows\System32 | 直接訪問 64 位文件 |
| 64 位 | C:\Windows\Sysnative | 不存在 | 僅 32 位進程可見 |
// 需以 32 位編譯運行
#include <Windows.h>
#include <Shlwapi.h>
#pragma comment(lib, "Shlwapi.lib")
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
wstring path = L"C:\\Windows\\System32\\notepad.exe";
if (PathFileExists(path.c_str())) MessageBox(0, L"存在", L"", MB_OK);
else MessageBox(0, L"不存在", L"", MB_OK);
path = L"C:\\Windows\\Sysnative\\notepad.exe";
if (PathFileExists(path.c_str())) MessageBox(0, L"Sysnative 存在", L"", MB_OK);
else MessageBox(0, L"Sysnative 不存在", L"", MB_OK);
return 0;
}
bcdedit, diskpart):需用 Sysnative 路徑或啟用「關閉重定向」Wow64DisableWow64FsRedirection。HKLM\Software 同理重定向到 HKLM\Software\Wow6432Node,用 KEY_WOW64_64KEY 旗標訪問 64 位視圖。SysWOW64,需注意腳本路徑。文件系統重定向是 64 位 Windows 兼容 32 位應用的核心機制。開發者必須理解 進程位數決定看到的視圖,並在需要跨位數訪問系統文件時,使用 Sysnative 別名或 API Wow64DisableWow64FsRedirection 繞過重定向。