I have a Java application, the Izpack
installer is wrapped with launch4j64bit
and then bundled as a self-extracting ZIP, created with WinRAR 5.20 using a method as described in an answer on How do I make a self extract and running installer?
It works, for me and most customers, but recently a few customers have reported errors like this:
Unable to access jarfile C:\Users\Ray\AppData\Local\Temp\RarSFX0\install.jar
I am unable to reproduce this error.
What could be causing this problem? Is it related to a Windows updates?
There is a only a problem with self-extracting version, a regular .zip file that users have to extract themselves works fine.
When I run the self-extracting archive it self-extracts correctly. So we have this folder structure:
JVM64
,install.jar
,setup.exe
andsetup.ico
.But for users having a problem it only extracts JVM64
:
Volume in drive C has no label.
Volume Serial Number is A663-4CEF
Directory of C:\Users\gcdr\AppData\Local\Temp
14/08/2018 21:40 <DIR> .
14/08/2018 21:40 <DIR> ..
14/08/2018 21:40 <DIR> RarSFX0
0 File(s) 0 bytes
Directory of C:\Users\gcdr\AppData\Local\Temp\RarSFX0
14/08/2018 21:40 <DIR> .
14/08/2018 21:40 <DIR> ..
14/08/2018 21:40 <DIR> JVM64
0 File(s) 0 bytes
I found for one user that disabling Norton AntiVirus allowed installation.
Now I use to submit each new version to Norton whitelist, but that option has gone.
Why could this be? Could there be some restriction with files called install.jar?
It took me a while to find out what really happens on running the SFX archive songkong-windows64.exe
.
First I detected that the temporary directory %TEMP%\RarSFX0
remains although it should be deleted by the SFX module at beginning of the SFX archive after installation finished without or with really installing the application. This was the first indication that something is wrong with setup.exe
executed by the SFX module according to SFX script commands inside archive comment file with content:
;The comment below contains SFX script commands
Setup=setup.exe
TempMode
Title=Unpacking SongKong Installer
So I created a batch file in directory containing setup.exe
with the following two lines:
@setup.exe
@echo Exit code is: %ERRORLEVEL%
I could see on execution of the batch file from within a command prompt window with user account control disabled (full granted administrative permissions without prompt) the dialog window to choose language for installation and at the same time in command prompt window the line:
Exit code is: 0
This was an indication for setup.exe
already terminated although the installation has not been done at all. So it looked like setup.exe
is just a small launcher application which does not really do the installation and terminates itself before installation finished or even really started. That is not good.
I used next free Sysinternals Process Monitor and looked on file system accesses logged by this tool on running songkong-windows64.exe
and get confirmed my supposition: setup.exe
just runs JVM64\bin\javaw.exe
with the arguments -jar
and install.jar
in the folder created by SFX module which is RarSFX0
, RarSFX1
, ...
That is very bad as written in help of WinRAR on using TempMode
for an SFX archive. It can be read after
In TempMode SFX needs to detect the termination of setup program to delete temporary files. Such approach works correctly if setup program is not terminated before installation is done. But sometimes the setup program starts a child process and terminates, expecting a child process to complete installation. In such case SFX deletes temporary files immediately after detecting that main setup application is finished, resulting in malfunctioning child process. So TempMode works correctly only with those setup programs, which do not start another processes or, at least, are not terminated until all child processes are finished.
It is clearly described in this paragraph that an application executed on using TempMode should not terminate itself before the entire installation process finished. But exactly this very important requirement is not fulfilled by setup.exe
which terminates immediately after starting real installation process.
The SFX module tries to delete the temporary directory RarSFX0
, but Windows prevents this because of JVM64\bin\javaw.exe
is still running and install.jar
is currently opened by Java executable. Well, depending on CPU and hard disk performance it could happen that all files in directory RarSFX0
including install.jar
could be already deleted before start of javaw.exe
really finished and this executable opened the file install.jar
while the subdirectory JVM64
can definitely never be deleted because of javaw.exe
is always running at this moment or scanned by an anti-virus application for harmful code.
The solution is not using the launcher application setup.exe
at all, but running javaw.exe
with the required arguments directly by the SFX module.
Let us assume the directory C:\Temp
contains:
The batch file CreateSFX.bat
contains following command lines:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "SourceFolder=%~dp0"
set "SourceFolder=%SourceFolder:~0,-1%"
set "CommentFile=%SourceFolder%\Setup.txt"
for %%I in ("%SourceFolder%") do set "ArchiveFile=%%~dpIsongkong-windows64.exe"
if not exist "%CommentFile%" (
echo ;The comment below contains SFX script commands
echo/
echo Setup=JVM64\bin\javaw.exe -jar install.jar
echo TempMode
echo Title=Unpacking SongKong Installer
)>"%CommentFile%"
del "%ArchiveFile%" 2>nul
rem Create solid RAR5 SFX archive using best compression with 64 MB dictionary size.
echo Create RAR SFX, please wait ...
"%ProgramFiles%\WinRAR\WinRar.exe" a -@ -afrar -cfg- -ep1 -ibck -iicon"%SourceFolder%\setup.ico" -k -m5 -ma5 -md64m -r -s -sfx"%ProgramFiles%\WinRAR\SfxModule\Default64.sfx" -x"%SourceFolder%\Setup.*" -x"%~f0" -tl -y -z"%CommentFile%" -- "%ArchiveFile%" "%SourceFolder%\"
rem Create ZIP SFX archive using best compression.
rem echo Create ZIP SFX, please wait ...
rem "%ProgramFiles%\WinRAR\WinRar.exe" a -@ -afzip -cfg- -ep1 -ibck -iicon"%SourceFolder%\setup.ico" -m5 -r -sfx"%ProgramFiles%\WinRAR\Zip64.sfx" -x"%SourceFolder%\Setup.*" -x"%~f0" -tl -y -z"%CommentFile%" -- "%ArchiveFile%" "%SourceFolder%\"
endlocal
This batch file creates on execution the file C:\Temp\SongKong64\Setup.txt
with following content in case of this file does not already exist:
;The comment below contains SFX script commands
Setup=JVM64\bin\javaw.exe -jar install.jar
TempMode
Title=Unpacking SongKong Installer
Important here is the different Setup SFX script command. The SFX module is instructed to run JVM64\bin\javaw.exe
instead of setup.exe
with the parameters -jar
and install.jar
. The SFX module makes the temporary directory the current directory before running javaw.exe
with the relative path.
Then the batch file runs WinRAR.exe
to create the SFX archive C:\Temp\songkong-windows64.exe
with excluding all Setup.*
files in C:\Temp\SongKong64
as well as the batch file CreateSFX.bat
.
The created RAR5 SFX archive with the used options using English WinRAR 5.60 has a file size of 111 MiB.
The batch file contains also the command line to create a ZIP SFX archive which would have a file size of 133 MiB.
On running the SFX archive created by this batch file the dialog window for selecting installation language opens and no file is deleted while this window is shown. On clicking on X button to cancel the installation, SFX module detects termination of javaw.exe
and deletes the temporary directory RarSFX0
as expected.
I have never completed the installation, but it should work as written here. I could not see with Process Monitor that setup.exe
defines special environment variables or modifies the current directory for javaw.exe
.
In case of javaw.exe
should be run with elevated permissions of a local administrator it is possible to add the WinRAR switch -iadm
to create an SFX archive which request the administrative access when started in Windows Vista and later.
For help on the used switches open in help of WinRAR from Contents tab via Command line mode and Switches the help page Alphabetic switches list and read from top to bottom with clicking on the switches used above for detailed description.
For understanding the used commands in the batch file and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
call /?
explains %~dp0
... drive and path of batch file ending with a backslash which is removed on next command line.del /?
endlocal /?
for /?
if /?
rem /?
set /?
setlocal /?