1

My program is a WPF app which is installed into Program Files (x86) folder, in this app I have a method called every 30 minutes to compared version of current app and version of .msi file in local folder. If version of .msi file is the lastest, app will run this .msi file to update version using the below code:

 Process installerProcess = new Process();
 ProcessStartInfo processInfo = new ProcessStartInfo();
 processInfo.FileName = "msiexec";
 processInfo.Arguments = $@"/i  {msiFilePath}  /q";
 processInfo.Verb = "runas";
 installerProcess.StartInfo = processInfo;
 installerProcess.Start();
 installerProcess.WaitForExit();

After updating I want to restart this app by using this code:

 Process.Start(Process.GetCurrentProcess().MainModule.FileName);
 Environment.Exit(0);

It is my problem from now: After updating version, my windows also restart and app doesn't auto launch when restarting finished

What I tried: I add log after called installerProcess.WaitForExit(); to notify app is updated successfully but in the log file I don't see any message. It's seem to windows restart before log is wrote.

What I want: my app can update the lastest version if exists and auto launch after update

Could anyone help me this problem?

HuynhMinh
  • 21
  • 5
  • As the application is still running when your MSI installs the new version, the Installer cannot replace the files and defers this to until a reboot. The Restart manager could be of help here, see also https://stackoverflow.com/questions/50917062/windows-installer-avoid-fileinuse-dialog-box-when-installing-a-package/50935008#50935008 – Klaus Gütter Jan 04 '23 at 07:40

0 Answers0