Reputation: 85875
I am trying to use this code from the tutorial Getting version from MSI without installing it, but when I try to add the "msi.dll" to Visual Studio 2010 as a reference I get this error.
Could not load file or assembly 'msi.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
This file may not be a managed assembly
Upvotes: 9
Views: 14356
Reputation: 718
var path = @"C:\Users\self\path\to\your\installFile.msi";
var view = ((dynamic)Activator.CreateInstance(Type.GetTypeFromProgID("WindowsInstaller.Installer")))
.OpenDatabase(path, 0)
.OpenView("SELECT Value FROM Property WHERE Property = 'ProductVersion'");
view.Execute();
string version = view.Fetch().StringData(1);
Console.WriteLine(version);
No references, no NuGets, no nothin'
Upvotes: 0
Reputation: 9
Add system.management
to references and include the namespace.
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Product where Name LIKE '%Your MSI Name%'");
foreach (ManagementObject obj in searcher.Get())
{
var version = obj["Version"];
}
This will give you version of any software installed in control panel.
Upvotes: 0
Reputation: 5059
Use "Microsoft.Deployment.WindowsInstaller.dll" from the Wix project's Deployment Tools Foundation (DTF). DTF provides a managed wrapper for much of msi.dll. Wix also provides helpful documentation.
Using DTF here is how I accessed the version number of an msi in C#
using Microsoft.Deployment.WindowsInstaller;
namespace Msi.Tables
{
public class PropertyTable
{
public static string Get(string msi, string name)
{
using (Database db = new Database(msi))
{
return db.ExecuteScalar("SELECT `Value` FROM `Property` WHERE `Property` = '{0}'", name) as string;
}
}
public static void Set(string msi, string name, string value)
{
using (Database db = new Database(msi, DatabaseOpenMode.Direct))
{
db.Execute("UPDATE `Property` SET `Value` = '{0}' WHERE `Property` = '{1}'", value, name);
}
}
}
}
Then from my application
string msiVersion = PropertyTable.Get("MyInstall.msi", "ProductVersion");
You can use Orca to view the msi tables. MSDN provides documentation on the Property Table. The details on SQL syntax for Windows Installer is also available in MSDN
Upvotes: 20
Reputation: 63105
to register asembly on 32 bit machine
REGSVR32 MSI.DLL
to register asembly on 64 bit machine
cd \windows\syswow64 regsvr32 C:\WINDOWS\system32\msi.dll
Upvotes: 3
Reputation: 177
From codeproject:
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).
I think you should add reference to your project in Solution Explorer (right click on References in SE -> Add Reference -> then browse to msi.dll in system32 directory).
Upvotes: 1