Sample code for 30+ languages & platforms
Perl

Create Self-Extracting Executable (Windows-only)

Demonstrates how to create a Windows self-extracting EXE.

Chilkat Perl Downloads

Chilkat2 Perl
use strict;
use warnings;
use Chilkat2;

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

my $zip = Chilkat2::Zip->new;
$zip->on(
    # Called periodically while a method runs (every HeartbeatMs milliseconds).
    AbortCheck => sub {
        return 0;   # return 1 to abort the method in progress
    },
    PercentDone => sub {
        my ($percentDone) = @_;
        print 'Percent Done: ', $percentDone, "\n";
        # Explicitly abort at 25% or greater.
        # Remove this to allow for the HTTP download to run to completion.
        if ($percentDone > 25) {
            return 1;   # abort the method in progress
        }
        return 0;   # return 1 to abort the method in progress
    },
    ProgressInfo => sub {
        my ($name, $value) = @_;
        print $name, ': ', $value, "\n";
    }
);

# Initialize the zip object.  Because we're creating
# a self-extracting EXE in this example, the filename
# passed to NewZip will never actually be created.
my $success = $zip->NewZip('notUsed.zip');
if (!$success) {
    print $zip->LastErrorText, "\n";
    exit;
}

# Append a directory tree.  The AppendFiles does
# not read the file contents or append them to the zip
# object in memory.  It simply appends references
# to the files so that when WriteExe (or WriteZipAndClose,
# or WriteZip, etc.) is called, the files are compressed
# and added to the archive.
my $recurse = 1;
$zip->AppendFiles('c:/temp/a/*', $recurse);

# Write "sfx.exe"
$success = $zip->WriteExe('c:/temp/sfx.exe');
if (!$success) {
    print $zip->LastErrorText, "\n";
    exit;
}