|
|
C# to Create Self-Extracting EXE with Custom Icon, Auto-Run Setup, etc.
Download Chilkat .NET for 2.0 / 3.5 Framework
Download Chilkat .NET for 1.0 / 1.1 Framework
C# sample program to create an SFX (self-extracting executable) with a custom icon, auto-run setup file, no-interface option, and other SFX options.
private void button1_Click(object sender, System.EventArgs e)
{
Chilkat.Zip zip = new Chilkat.Zip();
zip.UnlockComponent("30-day trial");
// Set this property to use an icon for the EXE that is created.
zip.ExeIconFile = "box.ico";
// Use this property to automatically unzip when the EXE is double-clicked.
// True = EXE has no interface, False (the default) = EXE includes interface
zip.ExeNoInterface = true;
// Causes the EXE to automatically unzip to a pre-set directory.
zip.ExeUnzipDir = "c:\\temp\\myApp";
// Causes the EXE to run a program (that was contained within the EXE)
// immediately after extracting.
zip.AutoRun = "Setup.exe";
// Parameters can be passed to the AutoRun program.
zip.AutoRunParams = "-x -a -b";
// Causes the creation of an EXE that has no interface,
// and automatically selects a temporary directory for
// unzipping.
//zip.AutoTemp = true;
// Initialize the Zip object and add some files.
zip.NewZip("blahblahblah.zip"); // <-- This is the file that would be written if WriteZip were called.
zip.AppendOneFileOrDir("Setup.exe",false);
zip.AppendOneFileOrDir("hamlet.xml",false);
// Create the self-extracting EXE.
bool success = zip.WriteExe("myPackage.exe");
if (!success)
{
MessageBox.Show(zip.LastErrorText);
}
else
{
MessageBox.Show("Created SFX!");
}
}
|