65.9K
CodeProject is changing. Read more.
Home

Getting version from MSI without installing it

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (5 votes)

Nov 17, 2008

CPOL
viewsIcon

41128

To get the version number from an MSI file without installing it.

Introduction

This article is used to fetch the version number from an MSI without installing the MSI.

Background

In C#, to access this, we need to have a reference to msi.dll which exists in the system32 folder of the system.

Using the Code

To access the version number or other product related stuff, we need to have the DLL reference in Visual Studio .NET.

DLL name: msi.dll (which exists in system32).

Type type = Type.GetTypeFromProgID("WindowsInstaller.Installer");

WindowsInstaller.Installer installer = (WindowsInstaller.Installer)

Activator.CreateInstance(type);

WindowsInstaller.Database db = installer.OpenDatabase(
    @"D:\SEDC\Services\MyCodeSetup.msi", 0);

WindowsInstaller.View dv = db.OpenView(
     "SELECT `Value` FROM `Property` WHERE `Property`='ProductVersion'");

WindowsInstaller.Record record = null;

dv.Execute(record);

record = dv.Fetch();

string str = record.get_StringData(1).ToString();
// here you will get the version number