Windows Installer, Java Installer, Freeware Installer
Home|Contact|Site Map|TOC|Search
Download  Features   Java  Licensing  Purchase  Testimonials  Support  Forums

How do I make my application to wait for the Updater to finish?

Answer

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

  • 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 };
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);

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

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

...
      

NoteThis code requires the following headers to be included:

...

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

using namespace std;

...
      
Privacy Policy | Windows Installer | Search Engine Ranking | Link Analyzer