Launch application with ShellExecuteEx API

It easy to launch an application and pass parameters using ShellExecuteEx API.  Following is a wrapper which prepares SHELLEXECUTEINFO structure and then calls ShellExecuteEx.

BOOL LaunchApplication(TCHAR* pStrPath, TCHAR* pStrParams)
{
SHELLEXECUTEINFO    shell_exec_info = {0};
shell_exec_info.cbSize = sizeof(SHELLEXECUTEINFO);
shell_exec_info.lpVerb = L”open”;
shell_exec_info.lpFile = pStrPath;
shell_exec_info.lpParameters = pStrParams;
shell_exec_info.fMask = SEE_MASK_NOCLOSEPROCESS;
return ShellExecuteEx(&shell_exec_info);
}

Another way which is more powerful but could be more complicated is to use CreateProcess API.

Comments are closed.