Skip to content

Instantly share code, notes, and snippets.

@yukitos
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yukitos/fb9bcb2a090ee51d8fcb to your computer and use it in GitHub Desktop.
Save yukitos/fb9bcb2a090ee51d8fcb to your computer and use it in GitHub Desktop.
Get ProductCode value from a specific msi file.
var msi = new ActiveXObject("WindowsInstaller.Installer");
var msiOpenDatabaseModeReadOnly = 0;
var db = msi.OpenDatabase("test.msi", msiOpenDatabaseModeReadOnly);
var view = db.OpenView("SELECT * FROM Property WHERE Property = 'ProductCode'");
view.Execute();
for (var r = view.Fetch(); r != null; r = view.Fetch()) {
WScript.Echo(r.StringData(1) + "=" + r.StringData(2));
}
view.Close();
using Microsoft.Deployment.WindowsInstaller.Linq;
using System;
using System.Linq;
class Program
{
static void Main(string[] args)
{
using (var db = new QDatabase("test.msi"))
{
var prop = db
.Properties.Where(i => i.Property == "ProductCode")
.AsEnumerable()
.First();
Console.WriteLine(prop.Value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment