Home » Visual Studio

RedirectStandardInput "A 32 bit processes cannot access modules of a 64 bit process."

Hi again,

After being able to resize and move around the console application I'm trying to tackle the redirect input.


I used the example given in this url:


and it worked great UNTIL I changed the "sort.exe" to be "cmd.exe" or a batch file.


Once I changed the process to start the "cmd.exe" or a very basic batch file (that only does "echo" and "set /p") I wasn't able to start the process anymore.


I went into debugging mode and I noticed that the process exits immediately after it "starts" (if it starts at all).


I dug a little dipper and I noticed that the process MainModule had this exception:

base {System.Runtime.InteropServices.ExternalException} = {"A 32 bit processes cannot access modules of a 64 bit process."}


I'm using Windows 7 Ultimate x64 and visual studio 2010.

I tried compiling the project with every combination of "platform" and "Active platform" (x64, x86, anyPCU for each) and all it got me is that when I used x64 in the "platform" (regardless of the active platform) I got the following exception instead:

base {System.Runtime.InteropServices.ExternalException} = {"Only part of a ReadProcessMemory or WriteProcessMemory request was completed"}


Google wasn't very helpful with either of those exceptions and only led me to a microsoft KB stating they have hotfix for windows visa  (but not for windows 7).


Needless to say that when I use the same code while "process.startinfo.redirectstandardinput = false" it starts the batch file and the "cmd.exe" just fine (without redirecting the input of course).


My question is, how can I redirect the input to a process that starts the "cmd.exe" or a batch file?


Thanks in advance,



I always try to help ;) sometimes I don't know how :(

4 Answers Found


Answer 1

Nobody seems to know the answer so allow me to post a bit  more info:

I have the following code:


Process myProcess = new

myProcess.StartInfo.FileName = @"cmd.exe"

myProcess.StartInfo.UseShellExecute = false

myProcess.StartInfo.RedirectStandardInput = true



I use the same code in both console  application and in windows  form application.

In both cases I have a breakpoint on the "myProcess.Start();" line and I step over it with F10.

In the console application  I have "myProcess.HasExited == false" (which is good) while in the windows application I have it as "myProcess.HasExited == true" (which is bad).

(Please note that if you don't use a breakpoint they both register as "myProcess.HasExited == false" and adding "Thread.Sleep(50);" right after it starts  reproduces the above behavior without a breakpoint).


When in my windows form application I tried both compiling to 32 bit and 64 bit application and I got the problems mentioned above:

When compiling to 64 bit (or AnyCPU) application the "myProcess.MainModule" exits  with exception: {"Only part of a ReadProcessMemory or WriteProcessMemory request was completed"}

When compiling to 32 bit application the "myProcess.MainModule" exits with exception: {"A 32 bit processes  cannot access  modules of a 64 bit process."}


I need to start  a process  of console application (batch file  or cmd.exe mostly but it can be anything the user chooses) from within my windows form application and send strings to it so it'll work like the user typed them in manually.


I would appreciate any and all help you can offer me on this.


Like I said before, I'm using visual  Studio 2010 on Windows 7 x64 ultimate  and my application needs to run on both Windows 7 x64  Ultimate and Windows Server 2008 R2 Enterprise.


Thanks in advance,


I always try to help ;) sometimes I don't know how :(


Answer 2

Can this be a .NET framework bug?

Answer 3

Considering this thread is the first hit in google I'm going to add all the info I have here just in case someone will be able to use it in the future.


In the .Net framework forum post: http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/4ce40b19-c442-4412-94b2-1ed24bdb9386

Jesse Houwingprovided a working code that redirects both input  and output.


Considering I don't want to redirect  the output and I want it to remain in the console  application window that solution doesn't help me much but it might help others.


It appears that the problem is reproduced only when you attempt to redirect the input alone.

When you combine the input with the output it all works fine.


If anyone has any idea on how to redirect the input ONLY I would love to hear it.


Answer 4

Hi daat99,

I replied you at here.



<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure