How can I resolve MSI paths in C#?

前端 未结 1 461
既然无缘
既然无缘 2020-12-21 09:21

I need to resolve target paths from an MSI database, outside of the installation. I am currently doing this using the Wix SDK by querying the database\'s Directory and File

相关标签:
1条回答
  • 2020-12-21 10:07

    I did the same thing you did when DTF first came out. I wrote all the queries and loops to get the data I was working for. And the performance was kind of painful.

    Then I noticed the InstallPackage class in the Microsoft.Deployment.WindowsInstaller.Package assembly. I felt kind of silly when I saw how fast and simple the following code is using that class:

    using System;
    using Microsoft.Deployment.WindowsInstaller;
    using Microsoft.Deployment.WindowsInstaller.Package;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (var package = new InstallPackage("foo.msi", DatabaseOpenMode.ReadOnly))
                {
                    foreach (var filePath in package.Files)
                    {
                        Console.WriteLine(filePath.Value);
                    }
                    Console.WriteLine("Finished");
                    Console.Read();
                }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题