Create self-extracting (SFX) archive
Aspose.ZIP allows creating a self-extracting (SFX) archive. This is a special kind of zipped file, which has a filename extension of.exe. You can unzip a self-extracting file by double-clicking it.
Creation self-extracting archive
To compose a self-extracting archive instantiate SelfExtractorOptions and pass it to ArchiveSaveOptions on saving.
1try (FileOutputStream zipFile = new FileOutputStream("archive.exe")) {
2 try (Archive archive = new Archive()) {
3 archive.createEntry("entry.bin", "data.bin");
4 ArchiveSaveOptions options = new ArchiveSaveOptions();
5 options.setSelfExtractorOptions(new SelfExtractorOptions());
6 archive.save(zipFile, options);
7 }
8} catch (IOException ex) {
9}
Running self-extracting archive
The archive you produce is executable and requires .NET Framework 2.0 or higher to run. Such frameworks are supplied with Windows Vista and above.
You can execute it as a regular program by double click, or run it via the command-line interface.
If you want to start extraction automatically specify -autoExtract
command-line option. Sample:
1C:\>archive.exe -autoExtract -password:T0p$ecret
Command line options for self-extracting archive
Option | Meaning | Sample |
---|---|---|
-autoExtract | Primary option - without it decompression does not start. Extraction starts automatically, other options apply. | sfx.exe -autoExtract |
-autoClose | Window closes when the extraction is complete. This option only makes sense if -autoExtract option is present. | sfx.exe -autoExtract -autoClose |
-forceOverwrite | Overwrites all existing files without prompt if there are any. This option only makes sense if -autoExtract option present. | sfx.exe -autoExtract -forceOverwrite |
-password: | Provides a password to encrypted entries. This option only makes sense if -autoExtract option is present. If you have spaces within the password quote it. | sfx.exe -autoExtract -password:T0p$ecret |
-destination: | Extracts files to the supplied directory. This option only makes sense if -autoExtract option is present. If you have spaces within the path quote it. | sfx.exe -autoExtract -destination:"C:\My Documents" |
You can use those options for composing Batch Script on Windows.