We help IT Professionals succeed at work.

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

romanm
romanm asked
on
Medium Priority
1,391 Views
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
	SHELLEXECUTEINFO info;
	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.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT;//SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE | SEE_MASK_WAITFORINPUTIDLE;
	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 )
			continue;
 
		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;
	ShellExecuteEx(&info);

Open in new window

Comment
Watch Question

Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
jkr
CERTIFIED EXPERT
Top Expert 2012

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

Commented:
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

Commented:
worked perfectly
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.