1
Reply

Reading MSI Tables in C#

Scott Furr

Scott Furr

Jul 27 2009 3:24 PM
11.6k

Hello all...I'm having an issue with some code.  What I'm trying to accomplish is opening an MSI file and reading the contents.  I'm using a reference to the WindowsInstaller Interop.  When I run this, I get an exception but I can't figure out where I'm going wrong.  Any help would be much appreciated.
 
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.IO;
using
WindowsInstaller;
 
namespace
msiReadTest1
{
   [System.Runtime.InteropServices.
ComImport(), System.Runtime.InteropServices.Guid("000C1090-0000-0000-C000-000000000046")]
   class Installer { }
 
   class Program
   {
      static void Main(string[] args)
      {
         WindowsInstaller.
Installer ins = (WindowsInstaller.Installer)new Installer();
         string strFileMsi = @"C:\Projects\msiReadTest1\msiReadTest1\bin\Debug\test.msi";
         Database db = ins.OpenDatabase(strFileMsi, WindowsInstaller.MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);
         View vw = db.OpenView(@"Select * FROM 'Property'"); // I'd like to pull from other tables besides Property as well
         vw.Execute(
null);
         Record rcrd = vw.Fetch();
         while (rcrd != null)
         {
            Console.WriteLine(rcrd.get_StringData(1).Split('|')[1]);
            rcrd = vw.Fetch();
         }
         vw.Close();
      }
   }
}

 

 The error message I'm receiving is:
Unhandled Exception: System.Runtime.InteropServices.COMException (0x80004005):
OpenView,Sql at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFla
gs flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) at WindowsInstaller.Database.OpenView(String Sql) at msiReadTest1.Program.Main(String[] args) in C:\Projects\msiReadTest1\msiReadTest1\Program.cs:line 20
 
Thanks in advance!

Answers (1)