7zip Self Extracting Archive (SFX) and .Net Installer
Asked Answered
G

2

6

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.

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.

I use 7zip to create the SFX as follows:

First, use 7zip to compress all of the files into a single archive:

7z.exe a -r AppInstallFiles.7z *

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:

;!@Install@!UTF-8!
Title="MyApp Installer"
ExecuteFile="setup.exe"
;!@InstallEnd@!

And I copy them with the line:

copy /b 7zS.sfx + config.txt + AppInstallFiles.7z MyAppInstaller.exe

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'

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.

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.

Greenleaf answered 12/7, 2012 at 19:46 Comment(1)
So, as a temporary solution, I've created a batch script which calls the two updates (WindowsInstaller and dotNetFx40_Client_x86_x64) with the /norestart flag. This isn't ideal, because a) this method doesn't automatically skip the .Net installer step if its already installed, and b) I can't pass a message informing the user to reboot before using the App. It also creates a cmd window, which would preferably be avoided.Greenleaf
H
2

The problem is that the SFX deletes extracted files after setup.exe finishes. To avoid this you may use the InstallPath parameter:

;!@Install@!UTF-8!
Title="MyApp Installer"
ExecuteFile="setup.exe"
InstallPath="%temp%\\My App"
;!@InstallEnd@!

But in this case extracted files will not be deleted at all. You could remove these files in your MSI, for example.

PS. If your customers will run the installer through a Remote Desktop Session you have also consider this issue

Hylophagous answered 13/7, 2012 at 13:54 Comment(4)
Actually, 7zip 9.20 doesn't have this flag, though I've seen it mentioned in multiple places (see sourceforge.net/projects/sevenzip/forums/forum/45798/topic/… - from the creator, "7-Zip SFX doesn't support "InstallPath" variable" and from the documentation, the only parameters are Title, BeginPrompt, Progress, RunProgram, Directory, ExecuteFile, and ExecuteParameters. I ended up doing something similar though - see my answer below.Greenleaf
Also, thanks for the heads up on the remote desktop issue, but thats not a problem for me. It also seems like I could extract to the app's (presumed) directory in program files to avoid it. though, that could be irritating to a user who installs the app elsewhere and doesn't expect the %programfiles%\MYAPP folder to exist.Greenleaf
We use the modified 7zip SFX from 7zsfx.info/en. It supports InstallPath and many other parameters.Hylophagous
@Serghei's link's changelog says the package's last edit was 2007.Blatt
G
2

I settled on a solution I found pretty acceptable. Since the issue results from the sfx temp folder deleting itself on the reboot, I run a batch file rather than setup.exe. The batch file moves copies everything in the temp directory to a new directory in temp, and calls setup from there:

::install.cmd, used to move the setup files to another directory before executing
xcopy /s * ..\MY_APP\
::use start to hide the cmd window
start ..\MY_APP\setup.exe

This folder then persists on reboot, allowing the setup to continue. As serghei notes, thats technically a problem, because it lasts until the user manually deletes the temp files, but its acceptable given the size of my app compared to modern hard drives

Greenleaf answered 13/7, 2012 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.