How to run a 64bit application from a 32bit compiled application?

Posted on 2009-02-17
Medium Priority
Last Modified: 2012-05-06
I have an application that needs to run msiexec.exe,\
this application is a 32bit built app, but when runnimg under windows 64bit should start the 64bit version of msiexec,
Currently using ShellExecuteEx the msiexec started is the 32bit version.
	// launch the .msi file,
	//  default action for opening a .msi file is launching it in msiexec.exe
	ZeroMemory( &info, sizeof(info) );
	info.cbSize = sizeof(info);
	// make sure we launch the installer as a separate process and we get a handle to it.
	info.lpDirectory = szPath;
	info.lpVerb = _T("open");
	info.lpFile = _T("msiexec.exe");
	info.nShow = SW_SHOW;
	TCHAR szMsiParam[MAX_PATH+128];
	_stprintf_s<sizeof(szMsiParam)/sizeof(TCHAR)>(szMsiParam, _T("/i \"%s\""), szMsi );
	wchar_t* lpCtx= NULL;
	wchar_t* lpOption= NULL;
	// first iteration, ((lpOption!=NULL)?NULL:lpCmdLine) , will evaluate as lpCmdLine
	// second and other iterations, lpOption is not null and expression will evaluate to NULL, as required.
	// when all parameters are gone, wcstok_s will set lpOption to NULL back, and loop will exit.
	while( NULL != (lpOption=wcstok_s( ((lpOption!=NULL)?NULL:lpCmdLine) , L" ", &lpCtx)) )
		// no '--' as start of option, invalid, try next one
		if( wcsncmp(L"--", lpOption, 2) != 0 )
		if( _wcsnicmp(L"silent", lpOption+2, 6) == 0 )
			// on '--silent' only
			_tcsnccat_s(szMsiParam, MAX_PATH+128, _T(" "), 1);
			_tcsnccat_s(szMsiParam, MAX_PATH+128, _T("/q/n"), 4);
	info.lpParameters = szMsiParam;

Open in new window

Question by:romanm
  • 2
LVL 12

Accepted Solution

Gideon7 earned 1000 total points
ID: 23666102
Call IsWow64Process to detect if you are running on 64-bit operating system. If yes, call Wow64DisableWow64FsRedirection before calling ShellExecEx.  This will allow your 32-bit app to call ShellExecEx to invoke a 64-bit executable file in the 64-bit  C:\Windows\System32.
See http://msdn.microsoft.com/en-us/library/aa365743.aspx
LVL 86

Expert Comment

ID: 23666757
Does it work to launch the 64bit .msi file using 'ShellExecuteEx()'?
LVL 12

Expert Comment

ID: 23668014
It should.  What it does it turn off the low-level redirection of "C:\Windows\System32" to "C:\Windows\SysWOW64" at the file-system level.   When redirection is turned off the low-level APIs (CreateFile, CreateProcess, etc) use the true 64-bit System32 folder.   Consequently high-level APIs like ShellExecute use it too.

Author Closing Comment

ID: 31548070
worked perfectly

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question