Skip to content

Switches

Chris Lake edited this page Jun 13, 2017 · 2 revisions

Command line switches

  • The module supports command line switches. The switches are NOT case sensitive. Multiple switches can be passed to the SFX archive sequentially. For example, "sfx.exe -ai -fm1 -gf+256-8" or "sfx.exe /ai /fm1 /gf+256-8" and even like "sfx.exe /Ai -fM1 /GF+256-8".
  • The module can pass switches to the executable program inside the SFX archive. The module looks for its native switches (listed on this page) in the command line until it finds the first unsupported switch. If such a switch found, the remaining switches are passed to the executable program inside the archive. For example, you have the following line in the config file: RunProgram="some_program.exe". If you launch the SFX with the command line like "sfx.exe -gm2 /key=1 /silent", the module recognizes its native switch '-gm2' and performs silent extraction of the archive content. The unsupported switches are passed "as is" to the executable in the archive, and therefore the program is invoked with the following parameters: "some_program.exe /key=1 /silent"
  • If you need to pass any natively supported switch to the executable inside the archive, you can use '-!' switch.

All switches passed to the executable inside the archive will be passed only to the FIRST program of the installation scenario you invoke. For example, you have the following lines in the config file:

RunProgram="\"%ProgramFiles%\\Setup.exe\""
RunProgram="\"regedit\" settings.reg"
AutoInstall="\"%ProgramFiles%\\Setup.exe\""
AutoInstall="\"regedit\" settings.reg"

After launching the SFX archive as "sfx.exe -gm2 -s -y", switches "-s -y" are passed to the first line, and the following commands are executed:

RunProgram="\"%ProgramFiles%\\Setup.exe\" -s -y"
RunProgram="\"regedit\" settings.reg".

If you invoke an automated scenario by launching the same SFX archive as "sfx.exe -ai -s -y", switches "-s -y" are passed to the third line, and the following commands are executed:

AutoInstall="\"%ProgramFiles%\\Setup.exe\" -s -y"
AutoInstall="\"regedit\" settings.reg"
Switch Description
-! Stops the command line parsing. All switches that appear in the command line after -! are passed to the first executable program ( RunProgram, ExecuteFile, AutoInstall or AutoInstallX).
In certain scenarios you may need to pass a switch that matches one of the native module switches. For example, you have "RunProgram="setup.exe -s" in the config file while you need to execute "setup.exe -s -y" (note, -y is a native module switch). In order to pass this switch to the executable, you need to use the following command line: "sfx.exe -gm2 -! -y". As a result, -y switch will be ignored by the module and passed to the executable inside the archive, so you get the command you need. Meanwhile, the module recognizes its native switch -gm2 and performs silent extraction of the archive content.
-ai Automated installation.
Specifies that the config file AutoInstall parameter will be used instead of RunProgram, ExecuteFile or AutoInstallX If AutoInstall is not specified, this switch will be ignored.
This switch automatically suppresses BeginPrompt dialog window (i. e. you do not need to specify -y switch.
-aiX Automated installation by the specified scenario. X can take the values from 0 to 9. You must have the invoked scenario in the config file (AutoInstallX parameter). In other words, you must have a line like AutoInstall7="auto_install.exe params for scenario 7" for the -ai7 switch to work. Otherwise, the error message is displayed.
Batch mode is possible for automated installation. You need to specify numbers of automated installations after -ai. For example, launching "sfx.exe -ai372" consequently invokes AutoInstall3 first, then AutoInstall7, and finally AutoInstall2. If either AutoInstallX contains multiple commands, they are run consequently before moving on to the next AutoInstallX.
This switch automatically suppresses BeginPrompt dialog window (i. e. you do not need to specify -y switch).
-fmX Appearance mode and display duration for FinishMessage dialog window, where X is:
  • 0 - do not display the window
  • 1 - display the window
  • N (N= 2...999) - display the window for N seconds. The countdown is displayed on the "OK" button. When time expires, the window closes and the module finishes its operation.
This switch OVERRIDES fmX prefixes in the config file. If FinishMessage is not present in the config file, -fmX are ignored.
-gfX Dialog windows display mode. You can alter or completely replace GUIFlags parameter specified in the config file.
The minus sign (-) removes flags, while the plus sign (+) adds flags. Examples of ALTERING flags:
  • -gf-8 - removes XP styles (minus in front of 8); the rest is taken from the config file
  • -gf+256 - adds confirmation dialog window when canceling installation or execration process; the rest is taken from the config file
  • -gf-8+256
    OR
  • -gf+256-8 - removes XP styles, adds confirmation dialog window when canceling installation, and the rest is taken from the config file
The module ignores attempts to remove a flag that is not set or add a flag that is already added. For example, in the config file you have GUIFlags="136" (8+128), and the SFX archive is launched as follows: "-gf-8+128-256+1024". As a result, flag 8 is removed, flag 1024 is added, and other flags are ignored (because flag 128 is already present in GUIFlags parameter, while flag 256 is absent and therefore can not be removed). Thus, the SFX archive is launched with GUIFlags="128+1024".
If you do not precede the first flag with the plus (+) or minus (-) sign, you can completely REPLACE GUIFlags parameter in the config file.
  • -gf64+8 - GUIFlags is made equal to 72 regardless of what specified in the config file
This switch ALTERS or REPLACES GUIFlags in the config file.
-gmX Extraction display mode, where X is:
  • 0 - the standard mode (native 7-Zip mode) with "Cancel" and "Close" buttons (the latter is in the upper right corner of the window)
  • 1 - display the extraction process, but hide the "Cancel" button and block the "Close" button as well the [ESC] key on the keyboard
  • 2 - hides the extraction dialog completely (silent mode)
This switch OVERRIDES GUIMode in the config file. This switch does not suppress BeginPrompt dialog window; you will need to use -ai, -aiX or -y switches for this.
-h or -? Displays a dialog window with HelpText and the "OK" button. If HelpText is not present in the config file, the following message is displayed: "No "HelpText" in the configuration file".
Closing the window completes the module operation (i. e. nothing will be unpacked or executed).
-nr "No Run" mode. Disallows running executables specified in RunProgram, ExecuteFile, AutoInstall or AutoInstallX, i.e. only the extraction is performed. In addition, shortcuts are not created, files are not deleted as well as the SFX archive, i. e. Shortcut, Delete and SelfDelete are not executed.
This switch is disabled when the SFX archive is extracted to a temporary folder.
-omX Overrides OverwriteMode parameter in the config file.
  • 0 - overwrite all files (default mode)
  • 1 - do not overwrite the existing files
  • 2 - overwrite only older files
-sdX Overrides SelfDelete parameter in the config file.
  • 0 - DO NOT DELETE SFX, even if SelfDelete="1" is specified in the config file
  • 1 - DELETE SFX, regardless of whether SelfDelete="1" is specified in the config file
-sfxconfig Lets you extract the config file from the SFX archive and save the file in the folder of your choice. The switch is followed by a space and the file name (or the file path and name). File name and extension can be arbitrary. Relative paths are allowed. If the folder does not exist, it will be created. If an attempt to create a folder or write on a medium (such as CD) fails, the error message is displayed.
Usage examples:
  • -sfxconfig config.txt - saves "config.txt" file in the current folder*
  • -sfxconfig \config.txt - saves "config.txt" file in the current folder disk root*
  • -sfxconfig ..\config.txt - saves "config.txt" file in a folder one level above the current folder*
  • -sfxconfig D:\DISTRIBUT\7-Zip\Folder name with spaces\setup.cfg - saves file "setup.cfg" file in "D:\DISTRIBUT\7-Zip\Folder name with spaces" folder
* See relative paths regarding the current folder.
‑sfxversion Displays a dialog window with the SFX module version and creation date.
Useful when the module resources have been modified by somebody.
-y Hides the following dialog windows: BeginPrompt, ExtractPath, combined BeginPrompt + ExtractPath and FinishMessage. The extraction window will be displayed (unless it is blocked by GUIMode parameter or -gm2 switch). If the extraction or installation process is interrupted, no CancelPrompt confirmation window is displayed. Should errors occur, error message windows are displayed regardless of this switch. Native 7-zip SFX switch.