title: 7zip Self Extracting Archive (SFX) and .Net Installer
body: <p>I am trying to create a self extracting archive for a windows application I have written. My app uses the latest .Net 4.0, and I want to include the .Net setup in the SFX installer. However, if the computer needs to install the .Net framework and reboot, it won't properly resume installing my application. I looked through the other sfx posts on the Stack sites, but none of them are problems involving a .Net installer as a prerequisite for the app.</p>
  
  <p>My project produces 4 files: "App Installer.msi" "setup.exe" "WindowsInstaller-KB893803-v2-x86.exe" (in the folder "WindowsInstaller3_1") and "dotNetFx40_Client_x86_x64.exe" (in the folder "DotNetFX40Client"), all of which I believe is standard.</p>
  
  <p>I use 7zip to create the SFX as follows:</p>
  
  <p>First, use 7zip to compress all of the files into a single archive:</p>
  
  <pre><code>7z.exe a -r AppInstallFiles.7z *
  </code></pre>
  
  <p>Next, I do a binary copy with the 7zS.sfx file (used to create a self extracting installer), my config file, and the archive. The config file is as follows:</p>
  
  <pre><code>;!@Install@!UTF-8!
  Title="MyApp Installer"
  ExecuteFile="setup.exe"
  ;!@InstallEnd@!
  </code></pre>
  
  <p>And I copy them with the line:</p>
  
  <pre><code>copy /b 7zS.sfx + config.txt + AppInstallFiles.7z MyAppInstaller.exe
  </code></pre>
  
  <p>The installer works perfectly on computers which already have .Net 4.0 My problem arises on computers which don't have the .Net Framework - I run the SFX, it extracts everything to a temp directory. Then, when setup.exe recognizes that the computer doesn't have .Net 4.0, it calls the .Net Installer. This extracts to its own temp directory and begins installing. On completion, it prompts for a reboot. Hitting "No" exits the entire install. Hitting "Yes" reboots the machine, and on logging back in there is an error: "An error occurred trying to install MyApp" with details of "Unable to locate application file 'App Installer.msi'</p>
  
  <p>It appears that the problem is, when the installer hands off to the .Net installer, and the .Net installer reboots, the temp directory containing the My App install files is deleted. I have tried switching from setup.exe to using "App Installer.msi," however this simply leads to the msi reporting that the computer doesn't have .Net and suggesting a web download. As I may be installing the app in offline situations, this won't work for me.</p>
  
  <p>Has anyone else tried to include the .Net installer before in a 7zip SFX, and if so how did they solve it? I'd prefer to keep using 7zip if possible, but will look into other tools if necessary.</p>