Note that there are some explanatory texts on larger screens.

plurals
  1. POShell Execute bring Window to front
    primarykey
    data
    text
    <p>I am using this function to call an executable from my msi. However the window for the executable hides behind my MSI window. Is there any way to bring it to the front. Sorry for the nobe question but I have tried minimizing all the windows just before the call to <code>ShellExecute</code> but that still does not bring the executable window to the front. Thanks</p> <pre><code>extern "C" UINT __stdcall InstallDrivers(MSIHANDLE hInstall) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; HANDLE hFile = INVALID_HANDLE_VALUE; BYTE* pbData = NULL; DWORD cbData = 0; char pwzFilename[MAX_PATH], szDriverType[MAX_PATH], pwzSentinelFilename[MAX_PATH], szIsInstalled[MAX_PATH]; LPWSTR szValueBuf = NULL, szIsHaspInstalled = NULL, szIsSentinelInstalled = NULL; hr = WcaInitialize(hInstall, "InstallDrivers"); ExitOnFailure(hr, "Failed to initialize"); WcaLog(LOGMSG_STANDARD, "Initialized."); WcaLog(LOGMSG_STANDARD, "%s", szValueBuf); CreateDirectory("C:\\Temp", NULL); strcpy_s(pwzFilename, "C:\\Temp\\HASPUserSetup.exe"); hr = ExtractBinary(L"Hasp", &amp;pbData, &amp;cbData); ExitOnFailure(hr, "failed to extract binary data"); if ((hFile = CreateFile(pwzFilename, GENERIC_WRITE,FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { PMSIHANDLE hRecord = MsiCreateRecord(0); MsiRecordSetString(hRecord, 0, TEXT("Could not create new temporary file")); MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_ERROR + MB_OK), hRecord); return ERROR_INSTALL_USEREXIT; } DWORD cbWritten = 0; if ( !WriteFile(hFile, pbData, cbData, &amp;cbWritten, NULL) ) { PMSIHANDLE hRecord = MsiCreateRecord(0); MsiRecordSetString(hRecord, 0, TEXT("Could not write to file")); MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_ERROR + MB_OK), hRecord); return ERROR_INSTALL_USEREXIT; } CloseHandle(hFile); strcpy_s(pwzSentinelFilename, "C:\\Temp\\sentinel_setup.exe"); hr = ExtractBinary(L"Sentinel", &amp;pbData, &amp;cbData); ExitOnFailure(hr, "failed to extract binary data"); if ((hFile = CreateFile(pwzSentinelFilename, GENERIC_WRITE,FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { PMSIHANDLE hRecord = MsiCreateRecord(0); MsiRecordSetString(hRecord, 0, TEXT("Could not create new temporary file")); MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_ERROR + MB_OK), hRecord); return ERROR_INSTALL_USEREXIT; } if ( !WriteFile(hFile, pbData, cbData, &amp;cbWritten, NULL) ) { PMSIHANDLE hRecord = MsiCreateRecord(0); MsiRecordSetString(hRecord, 0, TEXT("Could not write to file")); MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_ERROR + MB_OK), hRecord); return ERROR_INSTALL_USEREXIT; } CloseHandle(hFile); hr = WcaGetProperty(L"DRIVER", &amp;szValueBuf); ExitOnFailure(hr, "failed to get driver info"); wcstombs(szDriverType, szValueBuf, 260); if (strcmp(szDriverType, "Hasp") == 0) { hr = WcaGetProperty(L"SENTINELINSTALLED", &amp;szIsSentinelInstalled); ExitOnFailure(hr, "failed to get driver info"); wcstombs(szIsInstalled, szValueBuf, 260); if (strcmp(szIsInstalled, "Sentinel Protection Installer 7.6.5") == 0) { ShellExecute(NULL, "open", pwzSentinelFilename, NULL, NULL, SW_SHOWNORMAL); } ShellExecute(NULL, "open", pwzFilename, NULL, NULL, SW_SHOWNORMAL); }else { hr = WcaGetProperty(L"HASPINSTALLED", &amp;szIsHaspInstalled); ExitOnFailure(hr, "failed to get driver info"); wcstombs(szIsInstalled, szIsHaspInstalled, 260); if (strcmp(szIsInstalled, "Sentinel Runtime") == 0) { ShellExecute(NULL, "open", pwzFilename, NULL, NULL, SW_SHOWNORMAL); } ShellExecute(NULL, "open", pwzSentinelFilename, NULL, NULL, SW_SHOWNORMAL); } LExit: er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; return WcaFinalize(er); } </code></pre> <p>Updated Code:</p> <pre><code>extern "C" UINT __stdcall InstallDrivers(MSIHANDLE hInstall) { HRESULT hr = S_OK; UINT er = ERROR_SUCCESS; HANDLE hFile = INVALID_HANDLE_VALUE; BYTE* pbData = NULL; DWORD cbData = 0; char pwzFilename[MAX_PATH], szDriverType[MAX_PATH], pwzSentinelFilename[MAX_PATH], szIsInstalled[MAX_PATH]; LPWSTR szValueBuf = NULL, szIsHaspInstalled = NULL, szIsSentinelInstalled = NULL; SHELLEXECUTEINFO ShExecInfo; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = NULL; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = NULL; ShExecInfo.lpParameters = NULL; ShExecInfo.lpDirectory = NULL; ShExecInfo.nShow = SW_SHOWNORMAL; ShExecInfo.hInstApp = NULL; hr = WcaInitialize(hInstall, "InstallDrivers"); ExitOnFailure(hr, "Failed to initialize"); WcaLog(LOGMSG_STANDARD, "Initialized."); WcaLog(LOGMSG_STANDARD, "%s", szValueBuf); CreateDirectory("C:\\Temp", NULL); strcpy_s(pwzFilename, "C:\\Temp\\HASPUserSetup.exe"); hr = ExtractBinary(L"Hasp", &amp;pbData, &amp;cbData); ExitOnFailure(hr, "failed to extract binary data"); if ((hFile = CreateFile(pwzFilename, GENERIC_WRITE,FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { PMSIHANDLE hRecord = MsiCreateRecord(0); MsiRecordSetString(hRecord, 0, TEXT("Could not create new temporary file")); MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_ERROR + MB_OK), hRecord); return ERROR_INSTALL_USEREXIT; } DWORD cbWritten = 0; if ( !WriteFile(hFile, pbData, cbData, &amp;cbWritten, NULL) ) { PMSIHANDLE hRecord = MsiCreateRecord(0); MsiRecordSetString(hRecord, 0, TEXT("Could not write to file")); MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_ERROR + MB_OK), hRecord); return ERROR_INSTALL_USEREXIT; } CloseHandle(hFile); strcpy_s(pwzSentinelFilename, "C:\\Temp\\sentinel_setup.exe"); hr = ExtractBinary(L"Sentinel", &amp;pbData, &amp;cbData); ExitOnFailure(hr, "failed to extract binary data"); if ((hFile = CreateFile(pwzSentinelFilename, GENERIC_WRITE,FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { PMSIHANDLE hRecord = MsiCreateRecord(0); MsiRecordSetString(hRecord, 0, TEXT("Could not create new temporary file")); MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_ERROR + MB_OK), hRecord); return ERROR_INSTALL_USEREXIT; } if ( !WriteFile(hFile, pbData, cbData, &amp;cbWritten, NULL) ) { PMSIHANDLE hRecord = MsiCreateRecord(0); MsiRecordSetString(hRecord, 0, TEXT("Could not write to file")); MsiProcessMessage(hInstall, INSTALLMESSAGE(INSTALLMESSAGE_ERROR + MB_OK), hRecord); return ERROR_INSTALL_USEREXIT; } CloseHandle(hFile); hr = WcaGetProperty(L"DRIVER", &amp;szValueBuf); ExitOnFailure(hr, "failed to get driver info"); wcstombs(szDriverType, szValueBuf, 260); if (strcmp(szDriverType, "Hasp") == 0) { hr = WcaGetProperty(L"SENTINELINSTALLED", &amp;szIsSentinelInstalled); ExitOnFailure(hr, "failed to get driver info"); wcstombs(szIsInstalled, szValueBuf, 260); if (strcmp(szIsInstalled, "Sentinel Protection Installer 7.6.5") == 0) { AllowSetForegroundWindow(ASFW_ANY); ShExecInfo.lpFile = pwzSentinelFilename; ShellExecuteEx(&amp;ShExecInfo); /*ShellExecute(NULL, "open", pwzSentinelFilename, NULL, NULL, SW_SHOWNORMAL);*/ } AllowSetForegroundWindow(ASFW_ANY); ShExecInfo.lpFile = pwzFilename; ShellExecuteEx(&amp;ShExecInfo); /*ShellExecute(NULL, "open", pwzFilename, NULL, NULL, SW_SHOWNORMAL);*/ }else { hr = WcaGetProperty(L"HASPINSTALLED", &amp;szIsHaspInstalled); ExitOnFailure(hr, "failed to get driver info"); wcstombs(szIsInstalled, szIsHaspInstalled, 260); if (strcmp(szIsInstalled, "Sentinel Runtime") == 0) { AllowSetForegroundWindow(ASFW_ANY); /*ShellExecute(NULL, "open", pwzFilename, NULL, NULL, SW_SHOWNORMAL);*/ ShExecInfo.lpFile = pwzFilename; ShellExecuteEx(&amp;ShExecInfo); } AllowSetForegroundWindow(ASFW_ANY); ShExecInfo.lpFile = pwzSentinelFilename; ShellExecuteEx(&amp;ShExecInfo); /* ShellExecute(NULL, "open", pwzSentinelFilename, NULL, NULL, SW_SHOWNORMAL);*/ } LExit: er = SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE; return WcaFinalize(er); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload