我正在尝试通过调用CopyFileA将文件复制到C:\ windows \ system32 - 调试显示确实将字符串“C:\ windows \ system32 \ filename”发送到CopyFileA,但我的文件被复制到“ C:\ windows \ system32 \ sysWOW64 \ filename“而不是。有谁知道为什么会这样?
答案 0 :(得分:5)
在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 = GetModuleHandleW(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 = GetModuleHandleW(L"kernel32");
if (kernelMod)
{
fnWow64RevertWow64FsRedirection = (LPWOW64REVERTWOW64FSREDIRECTION)GetProcAddress(kernelMod, "Wow64RevertWow64FsRedirection");
if (fnWow64RevertWow64FsRedirection)
success = fnWow64RevertWow64FsRedirection(OldValue);
}
return success;
#endif
}
答案 1 :(得分:2)
只需要检查操作系统然后检查它并访问文件夹system32就像:
string os = Environment.GetEnvironmentVariable("WINDIR") + "\\SysWOW64";
if (Directory.Exists(os))
{
destinationDir = Path.Combine(Environment.ExpandEnvironmentVariables("%windir%"), "sysnative\\");
}
通过这个你可以复制system32文件夹中的文件。
享受: 阿里拉扎
答案 2 :(得分:1)
这个解决方案对我来说似乎更好: 归功于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 = GetModuleHandle(_T("kernel32"));
if (kernelMod)
{
if (toDisable)
fnWow64ChangeWow64FsRedirection = (LPWOW64CHANGEWOW64FSREDIRECTION)GetProcAddress(kernelMod, "Wow64DisableWow64FsRedirection");
else
fnWow64ChangeWow64FsRedirection = (LPWOW64CHANGEWOW64FSREDIRECTION)GetProcAddress(kernelMod, "Wow64RevertWow64FsRedirection");
if (fnWow64ChangeWow64FsRedirection)
success = fnWow64ChangeWow64FsRedirection(¶m);
}
return success;
#endif //WIN64
}