Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8686457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:51:17+00:00 2026-06-12T22:51:17+00:00

I need to extract the files from an MSI into a folder, but change

  • 0

I need to extract the files from an MSI into a folder, but change the directory structure of the files, all from within a C# application (ie: not by doing an admin install, or any other install of the MSI). Conceptually, I want to “unzip” the MSI’s embedded cab into the folder of my choosing. To do the extraction, I’m using the WiX 3.6 DTF libraries, but am unable to determine how to change the folder structure.

So, for instance, if I ran the MSI installer, the target folder for “Component1” would be c:\Program Files(x86)\Company Name\Demo Product Installer\Component1\, but at runtime in my extractor application, I’d like to put change that to c:\SomeOtherPlace\Demo Product Installer\Component1\, preferably by changing the APPLICATIONFOLDER directory path (see below).

For the MSI, I’ve defined the directory structure like this:

<Fragment>
  <Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="ProgramFilesFolder">
      <Directory Id="APPLICATIONFOLDER" Name="Company Name">
        <Directory Id="ProductFolder" Name="Demo Product Installer">
          <Directory Id="Cmp1Folder" Name="Component1" />
          <Directory Id="Cmp2Folder" Name="Component2" />
        </Directory>
      </Directory>
    </Directory>
  </Directory>
</Fragment>

Then, in the code that needs to extract the files, I’ve done this:

var msiFilePath = "myInstallerFile.msi";
var targetFolder = @"c:\SomeOtherPlace\";
using (var msiPackage = new InstallPackage(msiFilePath, DatabaseOpenMode.ReadOnly))
{
    msiPackage.WorkingDirectory = targetFolder;

    var dirMapping = msiPackage.Directories;    
    if (dirMapping.ContainsKey("APPLICATIONFOLDER"))                    
    {
        //This doesn't work, but represents what I hope to do:
        var oldInstallPath = dirMapping["APPLICATIONFOLDER"];                        
        oldInstallPath.TargetPath = targetFolder;                   
    }

    msiPackage.UpdateDirectories();                    
    msiPackage.ExtractFiles();                    
    msiPackage.Close();
}

Is there a way to modify the folder structure like this at runtime using the DTF objects? I know I can just move the files around after the fact, but if I can do it this way, it’d be much cleaner.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:51:19+00:00Added an answer on June 12, 2026 at 10:51 pm

    Based on the hint (“You might be albe to do it with in memory updates of the tables…”) from Chirtopher’s answer, I was able to find a working solution:

    var msiFilePath = "myInstallerFile.msi";
    var targetFolder = @"c:\SomeOtherPlace\";
    using (var msiPackage = new InstallPackage(msiFilePath, DatabaseOpenMode.Transact))
    {
        msiPackage.WorkingDirectory = targetFolder;
    
        var dirMapping = msiPackage.Directories;    
        if (dirMapping.ContainsKey("APPLICATIONFOLDER"))                    
        {
            //**** Modified code starts here ***//           
            // Changed the "APPLICATIONFOLDER" entry from "Company Name" to ".",
            // which is a special value to denote the extracted folder.
            var record = new Record(".", "APPLICATIONFOLDER");
            msiPackage.Execute("UPDATE `Directory` SET `DefaultDir` = ? WHERE `Directory` = ?", record);
            //**** Modified code ends here ***//
        }
    
        msiPackage.UpdateDirectories();                    
        msiPackage.ExtractFiles();  
    
        //Close **without** calling Commit() to ensure changes are not persisted                  
        msiPackage.Close();
    }
    

    Note that I also changed the DatabaseOpenMode to Transact.

    Of course, if you wanted to do more advanced changes to the folder structure, you’d have to modify/insert/remove additional records from the Directory table. (see http://msdn.microsoft.com/en-us/library/windows/desktop/aa368295(v=vs.85).aspx for reference)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to extract data from my MySQL database into multiple text files. I
I need to extract data from files in directory /tmp/log . I have no
I need to extract stills from video files. Currently I am using ffmpeg, but
I need to move all files from source folder to destination folder. How can
I need to extract all Icons sizes up to 256x256 from ico,exe,dll,icl files ExtractIconEx
I need to extract data from HTML-files. The files in question are, most likely,
I need to extract all the tags from an HTML file, In such a
I have an XML file and I need to extract testname from all the
I have a directory containing over 100 html files. I need to extract only
i have a rpm package, and i need to extract some files from it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.