PostHeaderIcon A Simple MFC Updater


  • This article is useful for small software;
  • actually it does not suit for the size of the software more than 5M(because it does not have friendly UI, but it is up to you!);
  • This Class does not contain process of UI, it processes in background;
  • This Class is from Codeproject or Codeguru,you can modify it yourself.

Today, many softwares update automatically, and each software should do as this way.

In MFC, How you can make your software update automatically,

maybe you can do it as the below steps:

  1. Retrieve the config file from the update server(make sure your custom client is connected with Internet);
  2. Check the version in the config file on server,compare to the existing application version;
  3. If an update is required, then download the new application from the update server;
  4. Switch in the latest application version with the existing version.

In this article, The Update Class named CAutoUpdater it contains the following functions:

// error type
enum ErrorType { Success, InternetConnectFailure, InternetSessionFailure,
  ConfigDownloadFailure, FileDownloadFailure, NoExecutableVersion,
  UpdateNotRequired, UpdateNotComplete };

/** main function for update,
   *in your class you can just call this only function to do your update
 ErrorType CheckForUpdate(LPCTSTR UpdateServerURL); 

/* Get the session between client and server with URL */
 HINTERNET GetSession(CString URL);

/* Test if the Internet is OK */
 bool InternetOkay();

/* download the version config file from server */
 bool DownloadConfig(HINTERNET hSession, BYTE *pBuf, DWORD bufSize);

/* download the executable file from server */
 bool DownloadFile(HINTERNET hSession, LPCTSTR localFile);

/* Get the version of the executable file in client which is running now */
 CString GetFileVersion(LPCTSTR file);

/* Compare two versions */
 int  CompareVersions(CString updateVersion, CString fileVersion);

/* Get the executable file in client which is running now,mainly is path */
 CString GetExecutable();

/* switch the executable file running in client with the the new version download file */
 bool Switch(CString executable, CString update, bool WaitForReboot);

AutoUpdater is available here, you can download it~

Here is the pics I used it:

the executable file, it comes with this:

CISE.exe version:

CISE.exe version:

you can see the version is

the config file of CISE.exe is only contans version information,it named update.txt

update_txt content

update_txt content


when click the exe, it just out with a simple dialog as follows:

update message dialog

update message dialog


When click the yes button, the update process runs in background(it does not has friendly UI).

when finished, the message dialog as follows:

update finished

update finished


when update finished, it goes to your application main UI,

and the files in your application folder is like this:

files in folder

files in folder


Now, it is your turn for it, good luck~


Leave a Reply

Your email address will not be published. Required fields are marked *



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2010 - C++ Technology. All Rights Reserved.

Powered by Jerry | Free Space Provided by