Create WinRAR SFX with admin rights by command line

valker picture valker · Mar 18, 2015 · Viewed 10.5k times · Source

I need to create WinRAR SFX archive that should work with admin permissions on Windows 7. I can make it with WinRAR GUI but I need to make it with WinRAR command line interface (to integrate it into build process). At the moment my script is like that:

rar.exe a -sfxdefault.sfx archive.exe some_file_to_be_in_sfx
rar.exe c archive.exe -zscenario.txt

while scenario.txt is

TempMode="Extract data from archive?","Title"

Any suggestions are welcome!

Answer

Mofi picture Mofi · Mar 18, 2015

First, take a look on question How can I automate the building of this Winrar Sfx File.

Second, if you have open the tab Advanced of Advanced SFX options dialog with the option Request administrative access in WinRAR GUI, there is a button Help which opens the help page for this dialog. This help page contains:

Request administrative access
Set this option if you wish to create SFX archive, which will request the administrative access when started in Windows Vista and later. This option does not change behavior of SFX archive in older Windows versions.

Corresponding command line switch is -iadm.

And this answers your question. -idam is on help page a hyperlink to the help page of this switch.

But the text file Rar.txt in program files folder of WinRAR containing an explanation of all commands and switches supported by console version Rar.exe does not list this switch nor does Rar.exe output it on running it from within a command prompt window with no parameters to get displayed the help for console version.

This means only WinRAR.exe supports the switch -iadm, but not console version Rar.exe. But this is no problem as WinRAR.exe can be executed also from within a batch file from console, best with using background process option -ibck.

Note: Best on creating the command line for WinRAR.exe is opening in help the page Alphabetic switches list via Contents - Command line mode - Switches and read from top to bottom while building the command line. Add the switches you need for creating the SFX archive.

For example:

WinRAR.exe a -cfg- -ep1 -iadm -ibck -inul -k -m5 -ma4 -md4m -r -s -sfxdefault.sfx -tl -y -zscenario.txt archive.exe some_file_to_be_in_sfx