Selbstextrahierende SFX-Archive erstellen

Aspose.ZIP ermöglicht die Erstellung eines selbstextrahierenden (SFX) Archivs. Dabei handelt es sich um eine spezielle Art von gezippten Dateien, die die Dateinamenerweiterung.exe haben. Sie können eine selbstextrahierende Datei entpacken, indem Sie auf sie doppelklicken.

Erstellung eines selbstextrahierenden Archivs

Um ein selbstextrahierendes Archiv zu erstellen, instanziieren Sie SelfExtractorOptions und übergeben Sie es beim Speichern an ArchiveSaveOptions.

1try (FileOutputStream zipFile = new FileOutputStream("archive.exe")) {
2    try (Archiv 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}

Selbstextrahierendes Archiv ausführen

Das von Ihnen erstellte Archiv ist ausführbar und erfordert .NET Framework 2.0 oder höher zur Ausführung. Solche Frameworks werden mit Windows Vista und höher mitgeliefert. Sie können es als normales Programm per Doppelklick oder über die Befehlszeilenschnittstelle ausführen. Wenn Sie die Extraktion automatisch starten möchten, geben Sie die Befehlszeilenoption -autoExtract an. Beispiel:

1C:\>archive.exe -autoExtract -password:T0p$ecret

Befehlszeilenoptionen für selbstextrahierende Archive

OptionMeaningSample
-autoExtract

Primary option - without it decompression does not start.

Extraction starts automatically, other options apply.

sfx.exe -autoExtract
-autoCloseWindow closes when the extraction is complete. This option only makes sense if -autoExtract option is present.sfx.exe -autoExtract -autoClose
-forceOverwriteOverwrites 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"

Sie können diese Optionen für die Erstellung von Batch-Skripten unter Windows verwenden.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.