Creating a real Setup

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
3 posts Page 1 of 1
Contributors
User avatar
DeveloperJacob
VIP - Donator
VIP - Donator
Posts: 87
Joined: Sun May 27, 2012 12:40 pm

Creating a real Setup
DeveloperJacob
Hello,

Today i´m going to teach you how to make a real setup.
In this tutorial i´m not going to explain how to make the gui but i´m going to explain the code.

This is also my entry for the Global Offensive competition by RunarM

Screenshots of the final result:

Welcome page:
Image

Select a Path page:
Image

Installing page:
Image

Finished Page:
Image


The first step is creating the GUI you want for your installer. If you want to use my gui, download the project files.

The next step is the code:

First add the following reference: Windows Script Host Object Model (COM)
Next add the following codes:

Imports:
Code: Select all
Imports System
Imports System.Net
Things that we need in the other part of the code:
Code: Select all
WithEvents CopyClient As New WebClient
    Dim Path As String
    Dim Source As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Sample\"
    Dim P As Integer = 1
    Dim X As Integer = 0
    Dim C As Boolean = False
    Dim Files As New ListView
The next code is for creating a shortcut:
Code: Select all
Dim IWshRuntimeLib As New IWshRuntimeLibrary.IWshShell_Class
    Private Function CreateShortCut(ByVal shortcutName As String, ByVal creationDir As String, ByVal targetFullpath As String, ByVal workingDir As String, ByVal iconFile As String, ByVal iconNumber As Integer) As Boolean
        Try
            If Not IO.Directory.Exists(creationDir) Then
                Dim retVal As DialogResult = MsgBox(creationDir & " does not exist. Do you wish to create it?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo)
                If retVal = DialogResult.Yes Then
                    IO.Directory.CreateDirectory(creationDir)
                Else
                    Return False
                End If
            End If
            Dim shortCut As IWshRuntimeLibrary.IWshShortcut
            shortCut = CType(IWshRuntimeLib.CreateShortcut(creationDir & "\" & shortcutName & ".lnk"), IWshRuntimeLibrary.IWshShortcut)
            shortCut.TargetPath = targetFullpath
            shortCut.WindowStyle = 1
            shortCut.Description = shortcutName
            shortCut.WorkingDirectory = workingDir
            shortCut.IconLocation = iconFile & ", " & iconNumber
            shortCut.Save()
            Return True
        Catch ex As System.Exception
            Return False
        End Try
    End Function
In the form closing event add this code:
Code: Select all
If C = True Then
            If MsgBox("Are you sure you want to cancel the installation", 36, "Cancel Installation") = MsgBoxResult.Yes Then
                C = False
            End If
        End If
        e.Cancel = C
The code for the Form_Load:
Code: Select all
page_Welcome.Visible = True
        page_Welcome.Location = New Point(0, 0)
        page_Welcome.Size = New Size(602, 383)

        For Each file In My.Computer.FileSystem.GetFiles(Source)
            Files.Items.Add(file)
        Next
For the "Browse" button in your form add this code:
Code: Select all
        Dim f As New FolderBrowserDialog
        With f
            .Description = "Choose Path"
            If .ShowDialog = Windows.Forms.DialogResult.OK Then
                TextBox1.Text = .SelectedPath
            End If
        End With
The following codes are for the CopyClient, just copy and past it into the code:
Code: Select all
    Private Sub CopyClient_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles CopyClient.DownloadFileCompleted
        X += 1
        If X > Files.Items.Count - 1 Then
            page_Finished.Visible = True
            page_Finished.Location = New Point(0, 0)
            page_Finished.Size = New Size(602, 383)
            P = 4
            Button9.Text = "Finish"
            Button9.Enabled = True
            Button8.Visible = False
            CreateShortCut("Program", My.Computer.FileSystem.SpecialDirectories.Desktop, Path & "\Program.exe", Path, Path & "\World-icon.ico", 0)
        Else
            CopyClient.DownloadFileAsync(New Uri(Files.Items.Item(X).Text), Path & "\" & Dir(Files.Items.Item(X).Text))
        End If
    End Sub

    Private Sub CopyClient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles CopyClient.DownloadProgressChanged
        ProgressBar1.Maximum = e.TotalBytesToReceive
        ProgressBar1.Value = e.BytesReceived
    End Sub
Next go to My Project -> Application and click on "View Windows Settings"

Then replace
Code: Select all
level="asInvoker"
with
Code: Select all
level="requireAdministrator"
The last thing is to create folder with the program name on your desktop with the bin/debug files in it and an Icon with .ico extension.

For the GUI and other things download the project files:
You do not have the required permissions to view the files attached to this post.
Image
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Re: Creating a real Setup
Dummy1912
well its seems a nice project :)
but seems it doesn't make the sample folder in program files
or even copy the files.

any idea?
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: Creating a real Setup
Shim
looks awesome :D
Find my programs on Softpedia
3 posts Page 1 of 1
Return to “Tutorials”