title: How to read MSI properties in c#
body: <p>I want to read properties of MSI in C# in desktop application.I am using following code:</p>
  
  <pre><code>    public static string GetMSIProperty( string msiFile, string msiProperty)
      {
          string retVal= string.Empty ;
  
          Type classType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
          Object installerObj = Activator.CreateInstance(classType);
          WindowsInstaller.Installer installer = installerObj as WindowsInstaller.Installer;
  
          Database database = installer.OpenDatabase("C:\\DataP\\sqlncli.msi",0 );   
  
          string sql = String.Format("SELECT Value FROM Property WHERE Property=’{0}’", msiProperty);
  
          View view = database.OpenView(sql);
  
          Record record = view.Fetch();
  
          if (record != null)
          {
              retVal = record.get_StringData(1);
          }
          else
              retVal = "Property Not Found";
  
          return retVal;            
      }
  </code></pre>
  
  <p>But I am getting error as System.Runtime.InteropServices.COMException was unhandled.</p>
  
  <p>the sqlncli.msi file is physically placed at c:\DataP location. While debugging I found that database does not contain the data after installer.OpenDatabase() statement.</p>
  
  <p>Please suggest me how to resolve this issue and get MSI properties in c#.</p>
  
  <p>Thanks in advance.</p>