Determining MSI version without installing it

I have an MSI file created in my C # Visual Studio 2010. The version is installed through the Version property. I wanted to know if there is a way to determine the version without having to install the file. Currently, when you right-click and view properties, it does not appear.

+6
source share
2 answers

Yes. I think you need to check the MSI database, but this requires either some API calls or a wrapper utility.

The Microsoft ORCA application should allow you to do this (although I have never tried this myself).

+3
source

The following code might be helpful. But remember that you first need to add the COM link to the Microsoft Windows Installer object library and add the WindowsInstaller namespace to your code. The following function may be required.

 public static string GetMsiInfo( string msiPath, string Info) { string retVal = string.Empty; Type classType = Type.GetTypeFromProgID( "WindowsInstaller.Installer" ); Object installerObj = Activator.CreateInstance( classType ); Installer installer = installerObj as Installer; // Open msi file Database db = installer.OpenDatabase( msiPath, 0 ); // Fetch the property string sql = String.Format("SELECT Value FROM Property WHERE Property='{0}'", Info); View view = db.OpenView( sql ); view.Execute( null ); // Read in the record Record rec = view.Fetch(); if ( rec != null ) retVal = rec.get_StringData( 1 ); return retVal; } 

If you need a version, specify the name of the MSI file you want, for example

 string version = GetMsiInfo( "d:\product.msi", "ProductVersion" ); 
+5
source

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


All Articles