为什么复制到system32会自动复制到sysWOW64?

我试图通过调用CopyFileA将文件复制到C:\ windows \ system32 – debugging显示确实string“C:\ windows \ system32 \ filename”被发送到CopyFileA,但我的文件被复制到“C:\ windows \ system32 \ sysWOW64 \ filename“。 有谁知道为什么会这样?

Solutions Collecting From Web of "为什么复制到system32会自动复制到sysWOW64?"

在64位Windows上,Windows为32位进程执行文件系统重定向。 要禁用,请调用Wow64DisableWow64FsRedirection

要使应用程序也能在32位Windows XP上运行,必须在运行时动态链接Wow64DisableWow64FsRedirection。 这是我使用的代码:

BOOL DisableWow64FsRedirection(PVOID* OldValue) { #ifdef WIN64 UNREFERENCED_PARAMETER(OldValue); return TRUE; #else typedef BOOL (WINAPI * LPWOW64DISABLEWOW64FSREDIRECTION)(PVOID *); LPWOW64DISABLEWOW64FSREDIRECTION fnWow64DisableWow64FsRedirection; HMODULE kernelMod; BOOL success = TRUE; kernelMod = GetmoduleeHandleW(L"kernel32"); if (kernelMod) { fnWow64DisableWow64FsRedirection = (LPWOW64DISABLEWOW64FSREDIRECTION)GetProcAddress(kernelMod, "Wow64DisableWow64FsRedirection"); if (fnWow64DisableWow64FsRedirection) success = fnWow64DisableWow64FsRedirection(OldValue); } return success; #endif } BOOL RevertWow64FsRedirection(PVOID OldValue) { #ifdef WIN64 UNREFERENCED_PARAMETER(OldValue); return TRUE; #else typedef BOOL (WINAPI * LPWOW64REVERTWOW64FSREDIRECTION)(PVOID); LPWOW64REVERTWOW64FSREDIRECTION fnWow64RevertWow64FsRedirection; HMODULE kernelMod; BOOL success = TRUE; kernelMod = GetmoduleeHandleW(L"kernel32"); if (kernelMod) { fnWow64RevertWow64FsRedirection = (LPWOW64REVERTWOW64FSREDIRECTION)GetProcAddress(kernelMod, "Wow64RevertWow64FsRedirection"); if (fnWow64RevertWow64FsRedirection) success = fnWow64RevertWow64FsRedirection(OldValue); } return success; #endif } 

只需要检查操作系统,然后检查它并访问文件夹system32就像:

 string os = Environment.GetEnvironmentVariable("WINDIR") + "\\SysWOW64"; if (Directory.Exists(os)) { destinationDir = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "sysnative\\"); } 

由此你可以复制system32文件夹中的文件。

享受:阿里·拉扎

这个解决方案对我来说似乎更好:信贷给Bevan Collins。

 BOOL changeWow64Redirection(PVOID& param, BOOL toDisable = true) { #ifdef WIN64 UNREFERENCED_PARAMETER(OldValue); return TRUE; #else typedef BOOL (WINAPI * LPWOW64CHANGEWOW64FSREDIRECTION)(PVOID *); LPWOW64CHANGEWOW64FSREDIRECTION fnWow64ChangeWow64FsRedirection; HMODULE kernelMod; BOOL success = FALSE; kernelMod = GetmoduleeHandle(_T("kernel32")); if (kernelMod) { if (toDisable) fnWow64ChangeWow64FsRedirection = (LPWOW64CHANGEWOW64FSREDIRECTION)GetProcAddress(kernelMod, "Wow64DisableWow64FsRedirection"); else fnWow64ChangeWow64FsRedirection = (LPWOW64CHANGEWOW64FSREDIRECTION)GetProcAddress(kernelMod, "Wow64RevertWow64FsRedirection"); if (fnWow64ChangeWow64FsRedirection) success = fnWow64ChangeWow64FsRedirection(&param); } return success; #endif //WIN64 }