views:

528

answers:

2

I am trying to run a 64 bit executable (java.exe) from our 32-bit .NET application. I am using Process class and invoking cmd /c <command name> in order to support all possible commands (like dir, cd etc).

The problem is that on my machine I installed 64-bit version of JRE and java.exe is only available from C:\Windows\System32 folder (x64). I have tried explicily starting 64 bit version of cmd.exe by calling C:\Windows\System32\cmd.exe but it gets redirected to SysWOW64 due to calling process being 32 bit.

Is there anything else I can do to get this to work?

EDIT The whole cmd /c thing is a bit of a red herring. It is not part of the problem, being able to run 64 bit executables is.

+5  A: 

You can temporarily disable filesystem redirection around the call to Process.Start, the appropriate API's to P/Invoke are Wow64DisableWow64FsRedirection and Wow64RevertWow64FsRedirection.

Another option is to use %windir%\sysnative, which is available on Windows Vista and above.

Michael
Sounds scary, i'll give it a go :)
Igor Zevaka
Indeed this works. I can't believe this is the official way of doing it - http://msdn.microsoft.com/en-us/library/aa365743%28VS.85%29.aspx - MSDN demonstrates using this function for precisely this purpose.
Igor Zevaka
Cool, sysnative worked too, i ll probably use that in the final version.
Igor Zevaka
A: 

Just in case this might help.. http://msdn.microsoft.com/en-us/library/aa384187(VS.85).aspx

Note that if the application is manifested to show the UAC prompt, then redirection will not take place. And also some folders are exempt from redirection.

Santhosh