How to make my application wait for the Updater to finish

When launched, the Advanced Installer 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:

1. Wait for the Updater to check for new updates.


// 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 };

if (!::CreateProcess(path, const_cast<LPTSTR>((LPCTSTR)cmd), NULL,
    NULL, FALSE, 0, NULL, NULL, &si, &pi))
  return ::GetLastError();

::WaitForSingleObject(pi.hProcess, INFINITE);


2. If new updates are found wait for the Updater to download and install them.


// Check mutex state only if the first process return code is 0. Return code 0 means
// that new updates are available
DWORD exitCode;
if (::GetExitCodeProcess(pi.hProcess, &exitCode) && (exitCode == 0))
  // 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"));

  HANDLE mutex = NULL;
  while (1)
    // Open the mutex and wait for the second updater instance to finish.
    mutex = ::OpenMutex(SYNCHRONIZE , FALSE, &mutexPath[0]);
    if (mutex)


  ::WaitForSingleObject(mutex, INFINITE);


NoteThis code requires the following headers to be included:


#include <windows.h>
#include <vector>

using namespace std;