Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if MSI requires a reboot before installation

If I launch an installer with MSIExec in quiet mode I can detect if a reboot is required to complete installation by checking if the exit code is 3010. But what I'd like to be able to do in a programmable form is test whether or not the installation of an MSI will require a reboot to complete before I launch the actual installer.

I've looked around at the MSI APIs:

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

I did think I could:

  1. Call MsiOpenPackage to get the installer ready to run
  2. Call MsiDoAction with the following: CostInitialize, FileCost, CostFinalize, InstallValidate
  3. Read records from the FilesInUse table (the following documentation on MSDN suggests this table is created after running CostFinalize/InstallValidate:

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

However that table doesn't actually appear to exist when I query for it during the installation process. Are there any other ways to check if a reboot will be required?

like image 984
Gareth Oakley Avatar asked May 28 '12 21:05

Gareth Oakley


People also ask

Is reboot required to complete installation?

Nope. Not at all. A reboot is the only and only way to modify a core system file or a file in use. Sure, you could technically end the process which is using that file, but quitting such processes while windows are running can completely crash your computer.

How do I check for pending reboots?

Testing for a a Pending Reboot (The Easy Way) Simply open up your PowerShell console and type Install-Script Test-PendingReboot . Install-Script will download my PowerShell script from the PowerShell Gallery to C:\Program Files\WindowsPowerShell\Scripts.

Where do I find MSI installation options?

The Windows Installer MSI options can be found by opening a command window (click the Windows Start button, type in cmd and press ENTER on the keyboard), and in the command window typing msiexec /? and pressing ENTER on the keyboard.


2 Answers

Gareth, theoretically you don't need to perform the actual install, you should execute just the actions until InstallValidate (included) because then the Files In Use messages appear. However, when the installation is performed with an an external UI handler the Windows Installer may behave a little different so that should be tested.

like image 132
Mihai Udrea Avatar answered Sep 21 '22 22:09

Mihai Udrea


The decision gets eventually made only during installation itself. As you know, it depends on circumstances like DLLs locked by a concurrently runnning application and therefore it is quite volatile.

There is no way that would guarantee you that you will not receive exit code 3010 after the real installation has completed.

That said, the exit code is not that closely bound to files in use. It may also indicate an inability to stop a service or perhaps some other transient or permanent condition. You can not learn whether a service could be stopped until you try.

like image 41
Jirka Hanika Avatar answered Sep 19 '22 22:09

Jirka Hanika