Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a 64-bit process from a 32-bit process

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.

like image 488
Igor Zevaka Avatar asked Jan 05 '10 01:01

Igor Zevaka


People also ask

Can 32-bit process launch 64-bit process?

Hi, the problem is simply, that the c:\windows\system32 directory in a 32 Bit application is the c:\windows\syswow64 directory - so the file cannot be found. But as soon as you start a 64 Bit application, you will have a 64 bit environment.

Can I run Windows 64-bit on a 32-bit processor?

No. You can only upgrade to another version of Windows with the same bit amount. If you wish to transition from a 32-bit version to a 64-bit version or vice versa, you would have to back up all of your files and perform a Custom installation of the version to install. Can I run 32-bit programs on a 64-bit computer?


3 Answers

What you do is you use %windir%\sysnative to resolve 64-bit CMD.EXE and then you launch your other 64-bit program via "/c" command line option.

like image 35
Nikolai Avatar answered Oct 01 '22 07:10

Nikolai


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.

like image 148
Michael Avatar answered Oct 01 '22 06:10

Michael


c:\>set proc
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 70 Stepping 1, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=4601

c:\>c:\windows\sysnative\cmd
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

c:\>set proc
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 70 Stepping 1, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=4601

c:\>
like image 32
DenNukem Avatar answered Oct 01 '22 06:10

DenNukem