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.
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?
EDIT
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.
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)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…