73

Google Chrome auto updates itself every five hours. I want to clone this exact functionality in my own application. What is a way to implement this functionality on Windows?

TravelDev
  • 102
  • 1
  • 10
John Shedletsky
  • 7,110
  • 12
  • 38
  • 63

3 Answers3

88

To replicate this update behavior you need two things:

  1. An updater application which checks for updates regularly. If an update is found it should install it automatically. Most commercial setup authoring tools include good updater applications. You can try writing an updater yourself, but it's not as easy as it sounds.

  2. Per-user installations for each of your product versions. A per-user installation writes data only in the user profile folder (AppData, Roaming folder etc.) and HKEY_CURRENT_USER. No Program Files or HKEY_LOCAL_MACHINE.

Per-user installations are required so you can perform the upgrade silently. If the installation is per machine, newer Windows version will show the elevation prompt and the user won't know what's happening.

The Updater

Some updaters use services. For automated updates this isn't a real solution because service installation needs Administrator privileges. So your install process and subsequent updates would show elevation prompts.

Another approach is to use a per-user Updater application. It doesn't require any elevation and it can be installed in the application folder. This type of updater can run either as a scheduled task or from within your application (execute it when your application starts).

In both scenarios you need to consider that the Updater may need to update itself. So the process which performs the update must be a temporary process (for example a temporary copy of the updater application). It also should run without elevation. This is why a service is not such a good idea. It would need to stop itself before the update, use a temporary process which handles the update and start again when finished.

Other things to consider are:

  • permissions issues (if the update process needs any privileges or elevation)
  • download locations
  • update detection mechanism (how the Updater detects if a new version should be installed or not)

The updates

A common misconception is that updates should be the application files (like the main application EXE). This is rarely the case because an update may need to overwrite more than just a file.

Most updates are installation packages (MSI for example) or patches (MSP). This is the best approach because they handle the entire update logic:

  • detect running applications
  • update resources
  • update the product information (shortcuts, Programs and Features applet in Control Panel etc.)

Installation packages also simplify the Updater application. With this type of updates the Updater needs only to detect available updates, download them and execute them.

Updates works in two ways:

Windows Installer has great support for both of them, so you could use MSI packages and MSP patches. It also supports silent installations, so all your Updater needs to do is execute the package with a command line parameter.

These packages also support per-user or per-machine installations through ALLUSERS property.

Update distribution

After you decide on an Updater and some update packages, you also need a distribution mechanism:

  • a way to inform the updater that updates are available (for example an updates information file on your server)
  • a way to detect if an update is installed or not (so it's installed only once)

All of this is not very easy. This is why a lot of products use third-party Updaters. Even some commercial setup authoring tools offer Updaters for your packages.

A custom updater is mostly used by very large companies with a lot of products, because the investment is worth it for them.

Cosmin
  • 21,216
  • 5
  • 45
  • 60
  • 11
    One comment: I would suggest avoiding a persistent updater program and use the task scheduler to run it at regular intervals instead. – Aaron Klotz Sep 23 '11 at 18:32
  • Great answer... but what about cross-platform needs? – Mr. Boy Nov 25 '11 at 16:26
  • Usually the client updater application is platform specific. So you need a different updater for each platform. The server part is the same for all platforms. – Cosmin Nov 25 '11 at 20:26
  • @CosminPirvu But, msp is too tricky to use reliably and often entire msi package(including cab files) is too large to deliver via web. So, I think neither of the two ways updates work suggested above are appropriate for me. How do you think about this? – David Johns Jul 31 '13 at 15:54
  • Unfortunately MSP patches are the only type of small updates that work out of the box with MSI-based installations. They work only for minor changes (for example a couple of files). But they do work if you don't try to include a lot of installer logic in them. The alternative is creating your own installers and updates. And this is usually not an easy task. – Cosmin Jul 31 '13 at 17:14
  • Writing an updater is certainly out of scope for most small application vendors given the complexity. Are there any recommendations on commercial setup authoring tools that really work on multiple windows versions(7 and 8) reliably?. – so_mv Aug 28 '14 at 05:30
  • Technically, you can use HKEY_LOCAL_MACHINE if your initial installation sets those keys to writable. Also, I think the using Task Scheduler your task could run as administrator without prompting user, although that's more useful in corp environment than consumer software. – Garr Godfrey Jan 14 '17 at 18:44
27

If you want to have the exact same functionality, you can. Google has open-sourced it.

https://github.com/google/omaha

  • 1
    However it seems this project is not updated any more... – Bob Cromwell Mar 05 '14 at 09:55
  • any update on this project? I tried to use this, but it's very difficult to configure and looks like this project has been discontinued by google. Any insights? – Pritesh Acharya Jun 26 '14 at 08:18
  • It has seen some more updates lately. It has definitely not been discontinued. I think Google are just developing it in-house and are "slow" to release what they have internally to the public. @PriteshAcharya I wrote a tutorial that should make it easier to configure: https://fman.io/blog/google-omaha-tutorial/ – Michael Herrmann Aug 05 '16 at 16:51
4

Try winsparkle - https://github.com/vslavik/winsparkle. It's a c++ library.

Y.N
  • 4,989
  • 7
  • 34
  • 61