1
Answer

Reading MSI Tables in C#

Photo of Scott Furr

Scott Furr

15y
11.6k
1

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)

0
Photo of Brandon Lewis
NA 603 116k 17y
I might be wrong, but I think its because you can't read XML from a URL. Maybe your mistaking XML for XHTML, which is eXtensibile HyperText Markup Language and its what 90% of web pages are built on these days unless you get into PHP or JavaScript and what not.
XML I believe is used primarily for web data storage on a user's PC and for small and simple database-like needs, it can be read by a web page, but is not an actual part of the build source code. Then again, I could be wrong but in all my web designing in college we never once used XML for the actual code construction of web pages.

-Scrap