How to read MSI properties in c#

后端 未结 5 1533
一生所求
一生所求 2020-12-31 11:13

I want to read properties of MSI in C# in desktop application.I am using following code:

    public static string GetMSIProperty( string msiFile, string msiP         


        
5条回答
  •  误落风尘
    2020-12-31 11:44

    Windows Installer XML's Deployment Tools Foundation (WiX DTF) is an Open Source project from Microsoft which includes the Microsoft.Deployment.WindowsInstaller MSI interop library. It's far easier and more reliable to use this to do these sorts of queries. It even has a LINQ to MSI provider that allows you to treat MSI tables as entities and write queries against them.

    using System;
    using System.Linq;
    using Microsoft.Deployment.WindowsInstaller;
    using Microsoft.Deployment.WindowsInstaller.Linq;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                using(var database = new QDatabase(@"C:\tfs\iswix.msi", DatabaseOpenMode.ReadOnly))
                {
                    var properties = from p in database.Properties
                                     select p;
    
                    foreach (var property in properties)
                    {
                        Console.WriteLine("{0} = {1}", property.Property, property.Value);
                    }
                }
    
                using (var database = new Database(@"C:\tfs\iswix.msi", DatabaseOpenMode.ReadOnly))
                {
                    using(var view = database.OpenView(database.Tables["Property"].SqlSelectString))
                    {
                        view.Execute();
                        foreach (var rec in view) using (rec)
                        {
                            Console.WriteLine("{0} = {1}", rec.GetString("Property"), rec.GetString("Value"));
                        }
                    }
                }
    
                Console.Read();
            }
        }
    }
    

提交回复
热议问题