1

I was using Winrar 3 to create self extractors and was using -sp flag to pass the arguments to the executable bundled inside. It was working fine. After I updated WinRar to 5.1, it stopped working. -sp<> flag is no longer working for me.

Does anyone else face a similar issue? Are there any other flags I can use to pass the parameters to the executable that is called by the self extractor. I read the following documentation about the available flags. http://www.winrar-tr.com/winrar/Help/ENG/html/HELPGUISFXCmd.htm

Vikram Singh
  • 1,726
  • 1
  • 13
  • 25

1 Answers1

3

The parameters for the executable can be specified directly in the comment file with the parameters for the SFX module.

Here is an example batch file demonstrating this technique:

@echo off
cd /D "%TEMP%"

rem Create the file for the SFX module with the SFX options.

echo ;The comment below contains SFX script commands.>TestSetup.txt
echo.>>TestSetup.txt
echo Setup=Test.bat Switch "One more parameter">>TestSetup.txt
echo Overwrite=1>>TestSetup.txt
echo Title=Test Installation>>TestSetup.txt
echo Text>>TestSetup.txt
echo {>>TestSetup.txt
echo ^<font face='Arial'^>An SFX test which just shows how SFX module runs the installer.^<br^>^<br^>Just click on button Install or hit RETURN.^</font^>>>TestSetup.txt
echo }>>TestSetup.txt

rem Create the batch file executed by SFX archive.

echo @echo %%0 %%*>Test.bat
echo @pause>>Test.bat
echo @del %%0 ^>nul>>Test.bat

rem Create the SFX archive.

RAR.exe a -sfx -c -zTestSetup.txt TestSetup.exe Test.bat

rem Delete the created batch and comment file.

del Test.bat
del TestSetup.txt

rem Run the self-extracting archive. User has to press only RETURN.

start /wait TestSetup.exe

rem Delete the self-extracting archive.

:DeleteLoop
del TestSetup.exe >nul
if exist TestSetup.exe goto DeleteLoop

This batch file first creates in directory for temporary files the text file TestSetup.txt with the content:

;The comment below contains SFX script commands.

Setup=Test.bat Switch "One more parameter"
Overwrite=
Title=Test Installation
Text
{
<font face='Arial'>An SFX test which just shows how SFX module runs the installer.<br><br>Just click on button Install or hit RETURN.</font>
}

Important for you is the line starting with Setup=.

  • Test.bat is the file to execute after extraction.
  • Switch is an option to pass as first parameter to Test.bat.
  • "One more parameter" is a second parameter with spaces inside to pass to Test.bat which must be enclosed in double quotes because of the spaces.

Next the batch file continues with creation of Test.bat with content:

@echo %0 %*
@pause
@del %0 >nul

This little batch file just outputs with first line how it was called by the SFX archive, next waits for a key hit by the user and last deletes itself. So it does not really matter to which directory the batch file is extracted. The default is current directory which is the directory of the temporary files.

Then the batch file creates the SFX archive TestSetup.exe. For details on the used switches see Rar.txt in program files directory of WinRAR.

Pleae note that the line with Rar.exe works only without modification if the program files directory of WinRAR is included in environment variable PATH, or Windows fails to find Rar.exe which is the console version of WinRAR. Modify the line with complete path to Rar.exe in double quotes to get this line of the batch file working independent on included directories in PATH.

After the SFX RAR archive is created, the files Test.bat and TestSetup.txt are deleted as not needed anymore.

Now the created SFX archive TestSetup.exe is called and after hitting key RETURN and you see that the Test.bat is called with the 2 parameters as specified in TestSetup.txt.

The batch file deletes finally also the created SFX archive.

Mofi
  • 46,139
  • 17
  • 80
  • 143
  • Thanks Mofi for the detailed description. I tried the same thing but it didn't work for me. I talked to an engineer at WinRar and he agreed that there was a bug in WinRar if the exe name was given inside double quotes. For example Setup=Test.bat was working but Setup="Test.bat" was not working. – Vikram Singh Jul 04 '14 at 11:17
  • Thanks! Answered my (similar) question – Roberto Bonini Sep 06 '15 at 23:46
  • Creating automated SFX archive, you might consider you should use -cfg- switch in order to avoid WinRAR's default settings dependency. Otherwise, WinRAR default settings might override your -zOptions.txt file content. At http://stackoverflow.com/a/24598044/378115 you can find another Mofi's example using the switch. Thanks Mofi – Julio Nobre Jan 27 '16 at 02:20