Ravid Goldenberg
Ravid Goldenberg

Reputation: 2299

C# - An approach for an automatic updater for a windows app

I have a windows app (written in C#...) that is installed on multiple remote workstations, the installation is being done by a MSI package.

An updated installation with changes to the program is being conducted from time to time, at this point, for each update, for each station we need to go to where the .MSI is located copy it and run it and only than start the app.

I would like that: whenever a user tries to start the app a background process will be initialized that will compare the installed version with the most recent version on the .msi location and if an update in needed will run the installation and than start the app.

The problem is that it can't be done from within the program since the program cannot be running when the installation/upgrade is taking place. Another consideration is that not all the stations operating at the same time so I can't schedule a timely upgrade, and it can't be done on stations boot since sometimes the updates needs to be done while the station is already operating(the station has several functions beside my app).

I have considered several approaches, it seems like a windows service could do the trick but I don't know if it could be "bound" to the initialize of the program and if it could suspend the program to do the necessary checks and updates and only than to restart the app.

I am open to all ideas so please don't feel obligated to my ideas...

Upvotes: 0

Views: 1700

Answers (3)

PhilDW
PhilDW

Reputation: 20780

Some comments and answers about the assumptions in the question:

"I would like that: whenever a user tries to start the app a background process will be initialized that will compare the installed version with the most recent version on the .msi location and if an update in needed will run the installation and than start the app."

The only time this is likely to be a useful approach is when the MSI is at a company's web server. The web site can host a web api that you send your ProductCode, Version, Upgrade to and it reports whether there is an upgrade, patch etc, and a location to download it from. In a company domain, just use AD, as has been said.

"The problem is that it can't be done from within the program since the program cannot be running when the installation/upgrade is taking place."

Why? Windows Installer will show FilesInUse dialogs for the end user to close down the running app. So this situation is already dealt with, and I'm not sure where you see a problem.

"...and if it could suspend the program to do the necessary checks and updates and only than to restart the app."

This is exactly what Restart Manager is for. Integrate your app with RM and Windows Installer will allow you to close down the app (saving whatever data you need to recover) and then restart you afterwards so you can recover your data and the user sees a minimal interruption. One example:

http://www.codeproject.com/Articles/772868/Restart-Manager-Support-For-Windows-Application

So I think TomTom's point is valid - there is no need to re-invent what AD does, or worry about how to update programs that are running, or how to restart a program after an installer update because all these problems were solved years ago.

Upvotes: 0

Sathik Khan
Sathik Khan

Reputation: 439

I'm updating my answer,

This is what we did....

  1. Create the Installer / Package ( you can install for all users here)
  2. Generate Bootstrapper (https://msdn.microsoft.com/en-us/library/ms165429.aspx You can use this tool create bootstrapper (http://www.softpedia.com/get/Programming/Other-Programming-Files/Bootstrapper-Manifest-Generator.shtml)

    1. Add dependencies and other conditions in bootstrapper

    2. Set the URL for updates

This will solve your problem. I was too quick to answer but this how we did.

Thanks.

Upvotes: 0

TomTom
TomTom

Reputation: 62093

at this point, for each update, for each station we need to go to where the .MSI is located copy it and run it and only than start the app.

Fire the guy pretending to be a system administrator.

Unless you have done something odd in your installer - it should be doable with your standard software distribution package. Heck, I can roll out updates with active directory ONLY and no third party software as long as the MSI allows administrative no ui installs.

You try to fix a non-problem. Software distribution is a solved solution for the last 15 to 20 years. MSI was particularly created to handle this issue because other approaches demonstrated issues.

So, whoever pretends to be the administrator on your company needs to get his act together and be one. Do nothing (except making a good MSI) and let the admin do his job.

Everything else just creates a lot of problems (at least in the cost side). And it is totally not needed.

Upvotes: 1

Related Questions