How
to Create Self-Extracting EXE in VB.NET
Download Chilkat .NET for 2.0 / 3.5 Framework
Download Chilkat .NET for 1.0 / 1.1 Framework
This is a
simple example demonstrating how to create a self-extracting EXE in VB.NET.
The result is an EXE that can be run without the .NET runtime or any system
DLLs (it is completely standalone).
There are
four subroutines in the source code below:
1) Create
a simple self-extracting EXE
2) Create a 128-bit AES encrypted self-extracting EXE
3) Create a self-extracting EXE that auto-unzips to a temp directory
and runs a Setup.exe
4) Create an encrypted + auto-unzip EXE.
' Create a simple self-extracting EXE. When the resultant EXE is run, it displays
' a dialog allowing the end-user to select a directory for unzipping.
Private Sub CreateExe1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateExe1.Click
Dim zip As Chilkat.Zip
zip = New Chilkat.Zip()
zip.UnlockComponent("unlockCode")
If (Not zip.OpenZip("sample.zip")) Then
Label1.Text = "Failed to open Zip"
Else
If (Not zip.WriteExe("sample1.exe")) Then
Label1.Text = zip.LastErrorText
Else
Label1.Text = "Created EXE!"
End If
End If
End Sub
' Create an encrypted self-extracting EXE. When the resultant EXE is run, it displays
' a dialog allowing the end-user to select a directory for unzipping, but it
' first prompts for a password which must match the password used when creating
' the EXE (in this example, the password is 'flubber').
Private Sub CreateExe2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateExe2.Click
Dim zip As Chilkat.Zip
zip = New Chilkat.Zip()
zip.UnlockComponent("unlockCode")
If (Not zip.OpenZip("sample.zip")) Then
Label1.Text = "Failed to open Zip"
Else
' OpenZip sets the properties to the characteristics of the Zip
' opened, so make sure to set these properties after opening
' the Zip.
zip.Encryption = 128
zip.SetPassword("flubber")
If (Not zip.WriteExe("sample2.exe")) Then
Label1.Text = zip.LastErrorText
Else
Label1.Text = "Created EXE!"
End If
End If
End Sub
' Creates a self-extracting EXE that when run, automatically unzips into an
' auto-selected temp directory and runs the Setup.exe contained within the
' EXE.
Private Sub CreateExe3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateExe3.Click
Dim zip As Chilkat.Zip
zip = New Chilkat.Zip()
zip.UnlockComponent("unlockCode")
If (Not zip.OpenZip("sample.zip")) Then
Label1.Text = "Failed to open Zip"
Else
' OpenZip sets the properties to the characteristics of the Zip
' opened, so make sure to set these properties after opening
' the Zip.
zip.AutoRun = "Sample/Setup.exe"
zip.AutoTemp = True
If (Not zip.WriteExe("sample3.exe")) Then
Label1.Text = zip.LastErrorText
Else
Label1.Text = "Created EXE!"
End If
End If
End Sub
' Creates an encrypted self-extracting EXE that when run, prompts for a password
' and then if the password is valid, automatically unzips into an
' auto-selected temp directory and runs the Setup.exe contained within the
' EXE.
Private Sub CreateExe4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateExe4.Click
Dim zip As Chilkat.Zip
zip = New Chilkat.Zip()
zip.UnlockComponent("unlockCode")
If (Not zip.OpenZip("sample.zip")) Then
Label1.Text = "Failed to open Zip"
Else
' OpenZip sets the properties to the characteristics of the Zip
' opened, so make sure to set these properties after opening
' the Zip.
zip.AutoRun = "Sample/Setup.exe"
zip.AutoTemp = True
zip.Encryption = 128
zip.SetPassword("flubber")
If (Not zip.WriteExe("sample4.exe")) Then
Label1.Text = zip.LastErrorText
Else
Label1.Text = "Created EXE!"
End If
End If
End Sub
Important: The download for this
example does not contain the ChilkatDotNet.dll which
must be downloaded and installed separately at http://www.chilkatsoft.com/downloads.asp.
Once installed, add a reference to the DLL in the project by following
the instructions at
http://www.example-code.com/vbdotnet/step2.asp