7zip - Create self-extracting Archive (sfx) with specified Extract path
I am trying to get the 7zip SFX archive to create an executable. I am able to get the executable. But when I run it, it give the downloads path for Extract to:. I would like to to change to %AppData%\Roaming by default. Screenshot below will give an idea of what I am trying to do.
There are no setup.exe or anything inside the archive, it has just few files that needs to go to Roaming folder. This is for many of our users, who can get this updates without them specifying a path. (It is always easy when users do not have to specify a path, otherwise, it is my experience that the users can pick most unusual paths!!)
Update
Here is what I have tried so far. my config file content is
;!@Install@!UTF-8!
InstallPath="%AppData%\\Roaming\\Notepad++"
;!@InstallEnd@!This is the command line call.
copy /b 7zS.sfx + config.txt + Installer.7z myinstaller.exeUnfortunately it does not work. It gives the following path. It should be %AppData%\\Roaming\\Notepad++.
4 Answers
Try 7z SFX Builder, it's free, supports command line parameters, and also you can specify extraction path on the GUI Main Tab:
2I would like to change the Extract Path to %AppData%\Roaming by default.
You need to download a "modified module" from 7z SFX Builder (sourceforge).
Check the links on the left for documentation (note these links and the text below is from )
In your configuration file:
InstallPath="%AppData%\Roaming"Configuration file parameters
InstallPath="path_to_extract"
Sets the extraction path. The extraction folder will not be deleted after the extraction.
If the
InstallPathvalue is not present in the config file or the path was deleted from the interactive extraction dialog, the archive will be extracted to a temporary folder. This temporary folder will be deleted after the extraction and execution of all commands.Environment variables are allowed (with the exception of
%%Tand variables defined inSetEnvironment, if%%Tis used in any of them). You MUST use DOUBLE backslashes in paths. For example:InstallPath="C:\\Windows\\system32\\test"or
InstallPath="%PROGRAMFILES%\\test"Relative paths are allowed. The current folder is the one from which the program launching SFX archive was executed. For example,
InstallPath="test"creates a folder with the name of "test" in the folder from which the program launching SFX archive was executed. All files will be extracted to the "test" folder. On the other hand,
InstallPath="."extracts the archive content to the folder from which the program launching SFX archive was executed. Also,
InstallPath="%%S"extracts the archive content to the folder where the SFX is located.
If all you need is to extract the archive content to a certain folder, you need to specify a value for
InstallPathin the config file.In this case you should not specify
RunProgramorExecuteFilein the config file.AutoInstallorAutoInstallXmay be specified in the config file, but should not be invoked via the command line or with the [SHIFT] key.If you specify
RunProgramorExecuteFileor invokeAutoInstallandAutoInstallX, the specified executable will be launched after the extraction.
Source Configuration file parameters
6Just use -y -o<PathToExtract>: Setup.exe -y -oc:\abc
(just in case anyone is trying to do this still)
I couldn't figure out how to make a SFX archive extract to a specific location, without also specifying a setup.exe or similar file.
I managed to achieve my goal by using the "-y -oPATH" switches shown here and storing a regular SFX archive inside a batch file (storing a file inside a batch file)
The result is not an EXE, but a CMD file. (but just a CMD file)
Method
- create source.exe
- create and edit script.cmd
- create combine.cmd
- execute combine.cmd
combine.cmd as the name suggests, combines script.cmd and source.exe to create output.cmd
output.cmd is the result, when run, it will copy source.exe out of itself to a temp location, run it with the arguments specifying the location, and then delete the temp file.
source.exe
This is a 7z SFX Archive created using the "make sfx archive" option. It contains all the files you want to extract.
script.cmd
you need to replace {target} with your desired location. eg: C:\Example
you must add an empty new line after exit /b before you save this file.
;;;===,,,@echo off
;;;===,,,findstr /v "^;;;===,,," "%-f0" > "%temp%\tempdata.exe"
;;;===,,,start /wait "" "%temp%\tempdata.exe" -y -o"{target}"
;;;===,,,del /f /q "%temp%\tempdata.exe"
;;;===,,,exit /bcombine.cmd
copy /a script.cmd /b source.exe /b output.cmd