文件被复制到 SysWOW64 而不是 System32 [英] File getting copied to SysWOW64 instead of System32

查看:27
本文介绍了文件被复制到 SysWOW64 而不是 System32的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的应用程序运行时,我必须将 psTool 实用程序复制到 System32 文件夹.
我在 64 位 Windows 7 上,每当我尝试通过 File.Copy 将 exe 复制到 system32 位文件夹时,该 exe 总是被复制到 SysWow64.

I have to copy a psTool utility to System32 folder when my application runs.
I am on 64 bit Windows 7 and whenever, I try to copy the exe to system32 bit folder through File.Copy, the exe always gets copied to SysWow64 instead.

当我在 destFile 上放置断点时,路径显示为 C:WindowsSystem32 但文件没有进入(进入 sysWow64).我已经尝试了 Special Folder SystemX86,但文件再次转到 sysWOW64.

When I put a breakpoint on destFile, the path is shown as C:WindowsSystem32 but the file does not go in there (goes to sysWow64). I have tried the Special Folder SystemX86, but the file again goes to sysWOW64.

string sourceFile = "C:inDebugsomexe.exe"
string destFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), utilityName);
File.Copy(sourceFile, destFile, true);

对我在这里缺少什么有什么建议吗?

Any suggestions what I am missing here?

编辑

正如下面的回答所指出的,正在发生文件系统重定向.我正在使用 Visual Studio 的默认设置为 64 位操作系统上的控制台应用程序开发应用程序.我不确定编译时必须保留哪些设置/开关,以便应用程序在 32 位和 64 位操作系统上都能运行.
基本上,它应该只将文件复制到 System32 ,而不管它是什么位操作系统.
在程序的后面,我必须通过命令行访问 psTools 实用程序,如果我将它放在 SysWOW64 中,则该实用程序不可用.如果我进行更改,以使用 SysWOW64 的 32 位 cmd.exe,这又将是特定于 64 位平台的内容,我不想选择.

As pointed out below in the answer, there's file system redirection taking place. I am developing the app with the default settings of Visual Studio for a console application on a 64 bit OS. I am not sure what settings/switches have to be kept while compiling, so that the application works both on 32 bit and 64 bit OS.
Basically, it should just set copy the file to System32 only regardless of what bit OS it is.
Later in the program, I have to access the psTools utility through command line which is not available if I place it in SysWOW64. If I make change, to use SysWOW64's 32 bit cmd.exe, this would again be something 64 bit platform specific, which I do not want to opt.

任何可以让应用程序在 32 位和 64 位上运行而没有问题的解决方案?我是否必须修改代码(如何?)还是必须修改此控制台应用程序项目的某些属性(哪些属性)?

Any solution which can have the app running both on 32-bit and 64 bit without an problems? Do I have to modify the code (how?) or do I have to modify some properties of this console application project (which properties)?

推荐答案

您与 文件系统重定向.

因为 %windir%System32 专为 64 位应用程序保留,在 64 位版本的 Windows 上,32 位应用程序尝试访问 %windir%System32 目录会自动透明地重定向到 32 位 %windir%SysWOW64 目录.

Because %windir%System32 is reserved exclusively for 64-bit applications, on 64-bit versions of Windows, 32-bit applications that attempt to access the %windir%System32 directory are automatically and transparent redirected to the 32-bit %windir%SysWOW64 directory.

首先,确保您的程序确实属于 64 位系统文件夹.Windows 执行这种自动重定向是有原因的.64 位版本的 Windows 上的 %windir%System32 文件夹中没有 32 位的内容.

First, make sure that your program actually does belong in the 64-bit system folder. Windows does this automatic redirection for a reason. 32-bit stuff does not go in the %windir%System32 folder on 64-bit versions of Windows.

如果您确定要将内容复制到 64 位系统目录中,您有几个选择.最简单的方法可能是将您的实用程序编译为 64 位应用程序.或者,您可以通过使用 %windir%Sysnative 而不是 %windir%System32 来告诉 WOW64 重定向器您知道自己在做什么并且不执行重定向.

If you're certain that you want to be copying stuff into the 64-bit system directory, you have a couple of options. The easiest is probably to just compile your utility as a 64-bit application. Alternatively, you can tell the WOW64 redirector that you know what you're doing and not to perform the redirection by using %windir%Sysnative instead of %windir%System32.

这篇关于文件被复制到 SysWOW64 而不是 System32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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