7zip - Create self-extracting Archive (sfx) with specified Extract path

15

2

Hello SuperUser Experts,

Thank you for your help in advanced. 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.

7zip settings

Extract To: dialogue box

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!!)

Thank you.

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.exe

Unfortunately it does not work. It gives the following path. It should be %AppData%\\Roaming\\Notepad++.

[Extract path]

Cricrazy

Posted 2016-05-19T14:20:00.310

Reputation: 826

This option is available with WinRAR but don't know about 7-zip. – Don't Root here plz... – 2016-05-19T14:28:02.760

Answers

7

Try 7z SFX Builder, it's free, supports command line parameters, and also you can specify extraction path on the GUI Main Tab:

Main tab

omegastripes

Posted 2016-05-19T14:20:00.310

Reputation: 353

omegastripes, it works great. Thank you. It has amazing amount of options. Thanks a lot. – Cricrazy – 2016-05-31T15:56:08.917

McAfee deletes the exe after installation because of a Trojan horse... – Lieven Cardoen – 2016-09-16T12:25:55.663

8

I 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 https://web.archive.org/)

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 InstallPath value 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 %%T and variables defined in SetEnvironment, if %%T is 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 InstallPath in the config file.

In this case you should not specify RunProgram or ExecuteFile in the config file. AutoInstall or AutoInstallX may be specified in the config file, but should not be invoked via the command line or with the [SHIFT] key.

If you specify RunProgram or ExecuteFile or invoke AutoInstall and AutoInstallX, the specified executable will be launched after the extraction.

Source Configuration file parameters

DavidPostill

Posted 2016-05-19T14:20:00.310

Reputation: 118 938

Thanks David. But can you tell me how to use configuration file? – Cricrazy – 2016-05-19T16:17:12.607

@Cricrazy See General information about the modified module which you have to download, and check the links on the left. Answer updated.

– DavidPostill – 2016-05-19T16:31:06.203

This 7-Zip config setting InstallPath is just what I am looking for. At moment I have to create a batch file to copy files from temporary extraction folder to our application's run time folder:

`;!@Install@!UTF-8! Title="Local Manager" InstallPath="C:\kiosk\update" RunProgram="7zbootstrap.bat" ;!@InstallEnd@!

@ECHO OFF REM 7zbootstrap.bat SETLOCAL SET update=C:\Kiosk\update XCOPY . %update%\ /S /E /I /F /Y CD %update% ECHO LAUNCHING AUTOUPDATE.BAT SCRIPT TIMEOUT /T 5 /NOBREAK autoUpdate.bat`

However, link no longer works.

– papertape – 2016-11-09T10:25:12.950

Can't get mini-Markdown to format the code block properly. Please amend if you know how. Thanks. – papertape – 2016-11-09T10:27:44.477

@papertape New link is https://sourceforge.net/projects/s-zipsfxbuilder/

– DavidPostill – 2016-11-09T11:01:18.003

@papertape Answer updated with working links. – DavidPostill – 2016-11-09T11:07:57.027

-2

Just use -y -oPathtoextract

e.g. Setup.exe -y -oc:\abc

user703610

Posted 2016-05-19T14:20:00.310

Reputation: 1

1can you give an example? what is e.g. and -oc? – Cricrazy – 2017-03-03T16:32:41.723

"e.g" stands for "expempli gratia", which basically means "for example". It is commonly used to indicate an example, just as you request. The answer is still bare of explanation and could use formatting, but it DOES include a full example. – music2myear – 2017-03-03T19:37:11.357

If you can elaborate on the command? You should always give a break down of what commands are going to do, as the user on the other end is going to be wary of commands with functions they don't know. – Service Manager – 2017-03-13T13:59:45.507

Command-line parameters get passed through to the contained Exe. – Kazark – 2017-04-04T19:35:02.957