How to get WinRar SFX to launch a bat file after extraction

OfficiallyFrex picture OfficiallyFrex · Sep 23, 2015 · Viewed 26.4k times · Source

So I need to get the SFX to extract to the location and then automatically launch the bat file from the folder it's just extracted to.

Hope someone can help.

Thanks, Tom

Answer

Mofi picture Mofi · Sep 23, 2015

In started WinRAR select the files or folders to put into an archive and click on button Add. Check option Create SFX archive.

Switch to tab Advanced and click on button SFX options. Switch to tab Setup and enter in field below Run after extraction the name of the batch file, with relative path if the batch file is not in root of the archive.

Click on button Help for details on this option.

Switch to tab Comment after finishing configuration of all SFX options and pressing button OK. You can see there now something like

;The comment below contains SFX script commands

Setup=Install.bat

You can save all options set for the creation of the SFX archive into a profile for making it easy to run WinRAR from within a batch file using the profile or quickly selecting the profile from within GUI.

It is of course also possible to define all settings directly on command line without using a WinRAR profile stored in Windows registry for current user.

The manual for the console version Rar.exe is the text file Rar.txt in program files folder of WinRAR.

The commands and options available for WinRAR.exe are documented in help of WinRAR. On tab Contents there is Command line mode listing all help pages useful to build the command line. For the switches start with Alphabetic switches list.

Edit:

If Install.bat is added to archive in a subfolder, it is necessary to specify the batch file with subfolder\Install.bat in Setup dialog of SFX options respectively the comment file.

And inside the batch file the command line cd "%~dp0" must be added at top to change current directory from target directory of extraction set by SFX module to the extracted subfolder containing the batch file.

By the way: Command processor of Windows does not allow execution of a batch file using a UNC path. So it is not possible to run the included batch file when the user chooses to extract the archive to a share on network using a UNC path.

See also

and other topics listed on this page on right side below Related.