views:

64

answers:

4

I have an application that runs on my computer and the computers of my colleagues at work. I sometimes push out updates for this application and want the application to detect this automatically (perhaps via database) and shut down and re-open to install the new updates.

I know how I can close an application, but don't know how I can re-open it because when it's not running, I don't know how to execute any code...

+1  A: 

How about creating a small update app. When your application detects an update it launches the update app and closes itself. The update app downloads and installs the update and then relaunches the main app and closes itself.

Alternatively if the application can update itself when it opens, why does it need to shutdown? Can't it just release any resources it's using etc and perform the update.

James Gaunt
The downside to "when it opens" is that the user may keep the application open for a long time, for weeks on end if they hibernate their machine or lock it when their finished with it, rather than shutting down. Something more pro-active is sometimes required
Rob
I agree. But seems his app doesn't need to be closed to update, since it updates itself on startup - just questioning why it can't update itself at any time with a little resource management.
James Gaunt
A: 

The process you really need to have is something like this:

  1. Application detects an update is required and executes an Update Application and then exits itself
  2. Update application downloads and installs the update
  3. Update application restarts the "main" application

The "Update application" may need administrative privileges to run if you're updating files on a Vista/Windows7 machine due to UAC, so you'd probably want to embed a manifest to help solve that.

To start another process, the code you'll want to execute is System.Diagnostics.Process.Start(), for example:

Process p = new Process();
p.StartInfo.FileName = "C:\\Windows\\System32\cmd.exe";
p.Start();
Rob
+2  A: 

ClickOnce handles updating an application very well. I don't see a problem here, if the user finds that the application is not working (because you have made a change server-side, that warrants them to update the client), they will restart the application and be prompted by the ClickOnce update mechanism to say an update is available (if this has been set up), once the application starts again.

The only way you could tell whether the application was due for an update, whilst the application in question is still running, is to poll the ClickOnce deployment file on the server and compare the version number against the current deployment. Not advisable.

Edit:

Another way to ensure that your users always have the most up-to-date version, is to not include a persistent deployment file and make the user always run from the launch page on your website. This would only dish out the latest and greatest version.

fletcher
http://msdn.microsoft.com/en-us/library/ms404263.aspx goes into how to configure clickonce to check for updates on specified intervals.
Tim Coker
ClickOnce continues to surprise me. I keep finding posts about these little features.
fletcher
A: 

If you are using ClickOnce (and your tag suggests you are?) then you can configure it so your application checks for updates on start-up.

Peter Kelly