Detect if MSI requires a reboot before installation

If I run the installer with MSIExec in silent mode, I can determine if a reboot is required to complete the installation by checking if it has an exit code of 3010. But what I would like to do in programmable form is a test, regardless of whether to install msi reboot to complete before , I run the actual installer.

I looked at the MSI API:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa369426(v=vs.85).aspx

I really thought I could:

  • Call MsiOpenPackage so that the installer is ready to run.
  • Call MsiDoAction as follows: CostInitialize, FileCost, CostFinalize, InstallValidate
  • Reading records from the FilesInUse table (the following MSDN documentation assumes that this table is created after running CostFinalize / InstallValidate:

http://msdn.microsoft.com/en-us/library/aa369546(VS.85).aspx

However, this table does not actually exist when I query it during the installation process. Are there other ways to check if a reboot is required?

+4
source share
3 answers

The decision is ultimately made only during installation. As you know, this depends on circumstances such as DLLs blocked by the simultaneously executed application, and therefore it is quite volatile.

There is no guarantee that you will not receive exit code 3010 after the actual installation is complete.

However, the exit code is not so closely related to the files used. It may also indicate the inability to stop the service or, possibly, some other temporary or permanent condition. You cannot find out if the service can be stopped until you try.

+2
source

Gareth, theoretically you do not need to perform the actual installation, you should only perform the actions before InstallValidate (included), because the message β€œUse files” appears. However, when the installation is performed using an external user interface handler, the Windows installer may behave a little differently, so it should be checked.

+4
source

Jirka is right about volatility - a reboot is required - all sorts of things can happen during the installation process.

However, I think that I have a proximity to what I would like to do with another method:

  • Register an external UI handler for INSTALLLOGMODE_RMFILESINUSE
  • Capturing INSTALLMESSAGE_RMFILESINUSE Messages
  • If I capture any INSTALLMESSAGE_RMFILESINUSE messages, return -1 and exit the installation before the file copy operations continue

That way I can try to install the background image of the software, but if for some reason it seems like I cannot complete the installation, I can hold back. I think that maybe I can roll back using the MsiBeginTransaction and MsiEndTransaction functions if I ended up in a user state that locked the file after the start of copying.

+1
source

Source: https://habr.com/ru/post/1414775/


All Articles