How do I make my application to wait for the Updater to finish?AnswerWhen launched, the Auto Updater checks for new updates. In this phase it runs from its normal location (where it was installed by your package). If new updates are found, the Updater copies itself to a temporary location and downloads and installs the updates running from there. In order to make your application wait for the Updater you must do the following:
...
// Customize this path to match the updater's normal location.
// The location where it was installed by your package
TCHAR * path = _T("C:\\Programs Files\\Your Company\\Your Application\\Updater.exe");
// Command line option for the updater
TCHAR * cmd = _T("updater.exe /checknow");
...
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
if (!::CreateProcess(path, const_cast<LPTSTR>((LPCTSTR)cmd), NULL,
NULL, FALSE, 0, NULL, NULL, &si, &pi))
{
return ::GetLastError();
}
::WaitForSingleObject(pi.hProcess, INFINITE);
...
...
// Compute the mutex name from normal path.
// The below code replaces the "\" character with "_" and the "exe"
// extension with "mtx"
vector<TCHAR> mutexPath;
mutexPath.resize(lstrlen(path) + sizeof(TCHAR));
::lstrcpy(&mutexPath[0], path);
TCHAR * p = &mutexPath[0];
int lastDot = -1;
while(*p++ != _T('\0'))
{
if (*p == _T('\\'))
*p = _T('_');
if (*p == _T('.'))
lastDot = static_cast<int>(p - &mutexPath[0]);
}
p = &mutexPath[0];
if (lastDot >= 0)
p[lastDot] = _T('\0');
::lstrcat(p, _T(".mtx"));
// Open the mutex and wait for the second updater instance to finish.
HANDLE mutex = ::OpenMutex(SYNCHRONIZE , FALSE, &mutexPath[0]);
::WaitForSingleObject(mutex, INFINITE);
...
...
#include <windows.h>
#include <vector>
using namespace std;
...
| |
| Privacy Policy | Windows Installer | Search Engine Ranking | Link Analyzer | ||
| © 2002 - 2008 Caphyon Ltd. Trademarks belong to their respective owners. All rights reserved. | ||