I’m using c#, .net 4, WIX 3.5, Windows Vista.
I have made my application compatible with RestartManager by p/invoking the RegisterApplicationRestart method and by handling the WM_QUERYENDSESSION and WM_ENDSESSION window messages (I return new IntPtr(1);).
If I try to update my application manually, then everything works as it should:
- Launch application;
- Launch msi file containing new app version;
- During the installation/update, I’m prompted to close the running application;
- Upon continuing the running app is closed, install completes, and the app is restarted;
If I try to update my application from the application itself, then I run into problems:
1) Launch application;
2) Download the new msi file;
3) Launch msi file with:
using (System.Diagnostics.Process p = new System.Diagnostics.Process())
{
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "msiexec";
p.StartInfo.Arguments = "/i \"" + downloadPath + "\" /passive";
p.StartInfo.UserName = "Administrator";
p.StartInfo.Password = securePassword;
p.Start();
}
4) Because I’m using passive mode, the application is closed automatically;
5) After the installation, my application is not restarted and under Event Viewer I have an
Event 10007 – Application or service ‘MyApp’ could not be restarted.
I have tried:
- Not to use passive mode for msiexec;
- Launch msiexec via cmd.exe (cmd.exe /C “msiexec /i ….”) – in the hopes that launching msiexec from another process would solve the problem;
- Wait for 60+ seconds before launching the msi update (shouldn’t be relevant in my scenario, but MSDN documentation has something about it…)
But none of the above has worked (always the same result).
Having to launch the setup with elevated permissions might have something to do with the issue, because during the manual update I get a warning in the Event Viewer – Application MyApp (pid 3220) cannot be restarted – Application SID does not match Conductor SID.
Despite this, restarting the app still works. Googleing the warning yields no good/specific results, only that this warning is probably caused by running the msi in an elevated prompt.
How do I fix (or workaround) this issue, so that I can update my application from the application itself and restart my application afterwards?
Edit – extra testing:
- There doesn’t seem to be a need to respond to WM_QUERYENDSESSION and WM_ENDSESSION messages, because application restart during a manual upgrade works without them, so we can rule them out;
- If I don’t provide administrator credentials to the application initiated upgrade and instead I type them in during the upgrade, then app restarting works;
- If I run an elevated command prompt and initiate an application upgrade from there (manually), then app restarting still works;
- In order for application upgrade to work at all under Standard user accounts (so far I tested under an Administrator account with UAC), then I also have to set
p.StartInfo.LoadUserProfile = true;. Otherwise nothing happens. (application restart still doesn’t work though); - I tried all other process StartInfo parameters that I could set – WorkingDirectory, Redirect, Verb
(= “runas”) – no change in results; - I installed Vista SP2 onto the virtual machine that I have been testing on (so far ran SP1), but no change;
- I performed an “automatic” application upgrade with verbose logging. In the end there was an error message – RESTART MANAGER: Failed while restarting applications. Error: 352. That error code is very generic (http://msdn.microsoft.com/cs-cz/library/aa373665), inorder to get more detailed info I would have to write my own installer that would call RmGetList after the error, then I might get more details (this though is something I’m not willing to do);
Edit 2 – msi log file:
http://mommi.planet.ee/muu/log.txt
Assuming that the manual process indeed works without any problem it seems that your need for Administrator privileges in combination with the “updating itself” leads to these problems. I see the following options:
create a batch file to execute the update
When you want to update call this batch file (with elevated privileges), make the app close itself… the batch file should wait some seconds, then check whether the app is still running (and close it in case) and then run the commandline you need to run
msiexec– don’t restart the app from within msiexec but after a successfull run ofmsiexecfrom the batch file.create a batch file which is always used to start the app
When the time comes to update you just end the app. Either the batch file check for an available update and applies it, starting the app after successfull update OR the app set some environment variable which is then accordingly processed by the rest of the batch file.