winrarself-extractingsfx

WinRar -sp<> flag not working with self-extractors


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


Solution

  • 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=.

    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.