How can I resolve MSI paths in C #?

I need to resolve target paths from MSI database outside of installation. I am currently doing this with the Wix SDK, querying the database tables and file tables and constructing paths from there, but path elimination looks like something that should already be built in. Is there a library that does this, even something unofficial, or am I sticking with it myself?

This question has already been asked for C ++, but the only answer somehow misunderstood the question about strings.

I really don't mind performance. My real problem is allowing special folders like ".: Fonts", ".: Windows", ".: WinRoot", etc. - which I can still do in my own code, but not very gracefully.

+3


source to share


1 answer


I did the same as in DTF. I wrote all the queries and loops to get the data I was working on. And the performance was painful.

Then I noticed the InstallPackage class in the Microsoft.Deployment.WindowsInstaller.Package assembly. I felt silly when I saw how fast and simple the following code uses this 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();
            }
        }
    }
}

      

+5


source







All Articles