Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch a Windows process as 64-bit from 32-bit code?

To pop up the UAC dialog in Vista when writing to the HKLM registry hive, we opt to not use the Win32 Registry API, as when Vista permissions are lacking, we'd need to relaunch our entire application with administrator rights. Instead, we do this trick:

ShellExecute(hWnd, "runas" /* display UAC prompt on Vista */, windir + "\\Reg", "add HKLM\\Software\\Company\\KeyName /v valueName /t REG_MULTI_TZ /d ValueData", NULL, SW_HIDE);

This solution works fine, besides that our application is a 32-bit one, and it runs the REG.EXE command as it would be a 32-bit app using the WOW compatibility layer! :( If REG.EXE is ran from the command line, it's properly ran in 64-bit mode. This matters, because if it's ran as a 32-bit app, the registry keys will end up in the wrong place due to registry reflection.

So is there any way to launch a 64-bit app programmatically from a 32-bit app and not have it run using the WOW64 subsystem like its parent 32-bit process (i.e. a "*" suffix in the Task Manager)?

like image 464
Jonas Avatar asked Oct 02 '08 13:10

Jonas


People also ask

Can 32-bit process launch 64-bit process?

A computer with a 64-bit processor can have a 64-bit or 32-bit version of an operating system installed. However, with a 32-bit operating system, the 64-bit processor would not run at its full capability.

Can a 32-bit application launch a 64-bit application?

The 64-bit versions of Windows don't provide support for 16-bit binaries or 32-bit drivers. Programs that depend on 16-bit binaries or 32-bit drivers can't run on the 64-bit versions of Windows unless the program manufacturer provides an update for the program.

How can I make 32-bit to 64-bit?

If you have a computer with a 32-bit setup, you can upgrade to the 64-bit version without acquiring a new license. The only caveat is that there is no in-place upgrade path to make the switch. The only option is to perform a clean installation of Windows 10.

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

To run a 64-bit version of Windows, your computer must have a 64-bit-capable processor.


1 Answers

Whether a 32-bit or 64-bit native (unmanaged) program is run depends solely on the executable. There are two copies of reg.exe, in C:\Windows\System32 (64-bit) and C:\Windows\SysWOW64 (32-bit). Because you don't specify a path, you're getting whatever appears first in the PATH environment variable, which is the 32-bit version for a 32-bit process.

You should really factor this function out into a separate program or COM object, and mark the program with a manifest, or launch the COM object using the COM elevation moniker.

like image 60
Mike Dimmick Avatar answered Sep 29 '22 12:09

Mike Dimmick