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

Posted on 2009-02-17
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
    LVL 12

    Accepted Solution

    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.
    LVL 86

    Expert Comment

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

    Expert Comment

    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.
    LVL 3

    Author Closing Comment

    worked perfectly

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    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.

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now