Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining the version of an MSI without installing it

I have an MSI file built from my C# Visual Studio 2010. The version is set 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 right click and view the properties it isn't displayed.

like image 406
probably at the beach Avatar asked Aug 22 '11 10:08

probably at the beach


People also ask

How do I tell what version of MSI I have?

When you right-click an MSI file and then click properties, certain information is displayed on the summary tab. I would like to display the version number from the "product properties" in InstallShield.

How do I decompile an MSI file?

"You can extract your MSI package to a local folder and then run . Net Reflector to decompile binaries you are interested at. Only managed code can be decompiled. If someone ran an obfuscator (such as Dotfuscator) on the code, though, all bets are off.

How do I know if I have an MSI installer?

You can tell if an installation is an . msi by the following ways. Go to www.appdeploy.com and select packages on the left side, you can find the package listed and, when selected, it will let you know if the file is an .exe or . msi.


1 Answers

The following code may be helpful. But remember that you should first add a COM reference to the Microsoft Windows Installer Object Library and add the WindowsInstaller namespace to your code. The following function may be what you need.

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 the version, pass in the name of the MSI file you want, e.g.

string version = GetMsiInfo( "d:\product.msi", “ProductVersion” );
like image 81
Gupta Avatar answered Sep 19 '22 17:09

Gupta