MSI get install arguments from registry

2019-08-02 13:57发布

问题:

We're actually writing PowerShell cmdlets to create a snapshot of installed (custom) MSIs. The cmdlets walk through a list of servers, check if MSIs of a given publisher are installed. If so, the MSI is copied from the remote machine to host executing the PowerShell cmdlet. So far so good. In the next stage we're planning to restore a system with the beforehand fetched MSI packages.

Our actual problem: Some of the MSIs need command line parameters for installation via msiexec. We searched the Windows registry if the arguments are stored somewhere, but we were not able to find them. We checked following paths:

 HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\*\InstallProperties
 HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*
 HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*

Does anybody knows if the install arguments, when installing an MSI via msiexec, are persisted on Windows?

The MSI packages get installed via:

  msiexec /i somePackage.msi /qn /norestart Arg1=1 Arg2=someTest Arg3=true

Thx

回答1:

Install Strings: As Chris has stated, the persisting of properties from an installation is an omission from Windows Installer - in my opinion too. I have implemented custom features for such persisting several times to work around the limitation for corporate deployment.

Uninstall Strings: Although there are no install strings / install command lines in the registry (that I know of), there are uninstall strings written to the registry as explained here.

Transforms: I want to add that if there are transforms applied during installation, then you can get the path to these via the MSI API. Applied transforms can make substantial changes to the MSI being installed, and is the heavy-weight approach to customizing deployment as compared to just setting PUBLIC PROPERTIES. More information here: How to make better use of MSI files (transforms section).

To retrieve a list of transforms applied to your MSI package on your box (there might not be any - most corporations use transforms for deployment), maybe try this VBScript which accesses the MSI COM API to get the information (rather than reading directly from the registry - which is not as good since raw values could be affected by implementation details not seen in the registry in clear text).

To run the script, copy / paste it into a *.vbs file on your desktop and double click to run. Output to msiinfo.csv. Open in Excel, a spreadsheet application or just Notepad:

Set fso = CreateObject("Scripting.FileSystemObject")
Set output = fso.CreateTextFile("msiinfo.csv", True, True)
Set installer = CreateObject("WindowsInstaller.Installer")

On Error Resume Next ' we ignore all errors

' Write headers
output.writeline ("ProductCode" & ", " & "ProductName" & ", " & "Version" & ", " & "Transforms")

For Each product In installer.ProductsEx("", "", 7)
   productcode = product.ProductCode
   name = product.InstallProperty("ProductName")
   version=product.InstallProperty("VersionString")
   transforms= product.InstallProperty("Transforms")
   output.writeline (productcode & ", " & name & ", " & version & ", " & transforms)
Next

output.Close


回答2:

Sadly, Windows Installer properties are NOT persisted. It's up to each MSI author to decide how he wants to save/retrieve (many don't know they need to) properties so that they are available in subsequent transactions.