Software Installer

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.
28 posts Page 1 of 3
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4390
Joined: Tue Aug 04, 2009 1:47 am

Software Installer
CodenStuff
Hello,

Its been a while since I posted any application tutorials because its been hard coming up with new things to do and I know quite alot of you are having the same trouble thinking of things to do. I hope this tutorial will give you some ideas or at the very least its something to get your teeth into and play about with ;).

OK im going to show you how you can make your very own custom made software installer.

First thing you need to do is startup VB and open a new windows forms project. Then add a "Button" to your form and thats pretty much all you need on your form for this tutorial, that was easy.

Now we move onto the code and to start with we need to add a public variable to hold our folder name so add this directly below "Public Class Form1":
Code: Select all
Public InstallFolder = "My Application"
Change "My Application" to any name you like, this is going to be the name of our application folder into which our application will be installed.

Then we are going to add a function that will do all the hard work for us so below the code you just added, add this entire code block:
Code: Select all
  Private Function ExtractResources(ByVal Resource As String) As String
        Dim ExtractFileTo As String = (My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\" & InstallFolder & "\") + Resource.Replace(Application.ProductName & ".", "")
        Dim CheckFile As New System.IO.FileInfo(ExtractFileTo)
        Dim SearchResourceFiles As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
        Dim PrepareResource As System.IO.Stream = SearchResourceFiles.GetManifestResourceStream(Resource)
        Dim bytesRead As Byte() = New Byte(PrepareResource.Length - 1) {}
        PrepareResource.Read(bytesRead, 0, bytesRead.Length)
        Dim SaveResource As New System.IO.FileStream(ExtractFileTo, System.IO.FileMode.Create)
        SaveResource.Write(bytesRead, 0, bytesRead.Length)
        SaveResource.Close()
        Return ExtractFileTo
    End Function
All that code does is finds and extracts the resource file that we want. In our case its going to extract all our application files just like any other installer does but ill explain more about that further on.

Now inside your "Button1_Click" event add this code:
Code: Select all
My.Computer.FileSystem.CreateDirectory(My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\" & InstallFolder & "\")
That code will create our application folder inside the windows "Program Files" directory, again just like any other installer.

Then still in the "Button1_Click" event add this code aswell:
Code: Select all
Dim EmbeddedFilesList As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
        For Each ResourceFile As String In EmbeddedFilesList.GetManifestResourceNames()
            If Not ResourceFile.Contains(".resources") Then
                ExtractResources(ResourceFile)
            End If
        Next
This code loops through all of our resource files and extracts them one at a time using our function which we added earlier.

Now for the very important part that makes this whole thing work. Because this is an installer we obviously need to include our application and any files required. So locate your application folder (the application that you want to have installed) and add your Application.exe and any dlls, images, text files and anything else thats inside your application folder and add them ALL as resources into this project.

THIS IS IMPORTANT:
After you have added everything into resources you should see a new "Resources" folder in the solution explorer at the top-right of your screen like this:

Image

You can see ive added my application and all the files that it needs as resources. Now once everything has been added you need to highlight/select ALL your resource files and take a look at the properties window directly below as seen in this image:

Image

You need to change the "Build Action" propertie to "Embedded Resource" and then save your project.

Thats it your finished :D you now have your very first custom made software installer.

I know it seems a bit basic just having 1 button but I did it this way so you can change/improve it to your own needs and requirements. You can add options to create shortcuts on the desktop and the start menu and even add status label or progress bar to show the installation progress and even add an uninstall feature.

I have added some of these features to the attached project file so you can get an idea of what you can do and just how easy it is ;).

Download:
CustomInstaller.zip
Happy coding cooll;
You do not have the required permissions to view the files attached to this post.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
AleRi8
Top Poster
Top Poster
Posts: 153
Joined: Sun Sep 20, 2009 2:30 pm

Re: Software Installer
AleRi8
Wow thanks a lot i always wanted to make a custom installer
check out my software
win7 itweaker basic £4.50
viewtopic.php?f=70&t=793
User avatar
TheET
VIP-Member
VIP-Member
Posts: 105
Joined: Sun Nov 01, 2009 2:41 am

Re: Software Installer
TheET
Hi CodenStuff , thanks for this great tutorial

I want to ask if a user who downloaded my custom installer for my application , the user machine(computer) do not have .Net 2.0 above and how can they run the installer ?

I am looking for a way which the installer can launch without .Net and check if see the machine got .Net install to ensure my application can work .

And also ,
I really want to know how you did CNS that can embed dll usercontrols into another application forms . I want to learn that because i am building a very complex software and dun want all the forms and codes in one exe file .

Hope you can post a tutorial about that asap as you said above "Its Hard To coming up new things to do" why don't post this tutorial .

Thanks so much CodenStuff ~!
:)
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

Re: Software Installer
hungryhounduk
Hi Codenstuff
Nice one, just did the tutorial and i worked a treat cooll;

Quality

Chris
Image
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4390
Joined: Tue Aug 04, 2009 1:47 am

Re: Software Installer
CodenStuff
Hello,

Thanks for the comments :D. I guess if you would have to include a link the .net redistributable with your installer just incase a user doesnt have it installed: http://www.microsoft.com/downloads/deta ... laylang=en most users will probably have it installed already anyway at some level.

I will post a tutorial on how to use add-ins when I have it all figured out and working properly cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4390
Joined: Tue Aug 04, 2009 1:47 am

Re: Software Installer
CodenStuff
Hello,

I made an update to my original source-code which adds Repair and Uninstall buttons to it. The buttons only show if the application has already been installed just like a normal installer.

Download:
CustomInstaller2.zip
I will post a tutorial later on how I did it cooll;
You do not have the required permissions to view the files attached to this post.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
TheET
VIP-Member
VIP-Member
Posts: 105
Joined: Sun Nov 01, 2009 2:41 am

Re: Software Installer
TheET
Thanks Codenstuff ,

Hope you can do it soon .

Codenstuff rocks !!!
User avatar
MiztaInsane
VIP - Donator
VIP - Donator
Posts: 13
Joined: Thu Jan 14, 2010 3:39 pm

Re: Software Installer
MiztaInsane
this is cool. how can we add a Progress Bar that show the progress?
User avatar
SlackBladder
Just Registered
Just Registered
Posts: 6
Joined: Thu Apr 22, 2010 9:29 am

Re: Software Installer
SlackBladder
brill, gonna need this for my project, when i finish ima upload onto this site to give back all this help you've given me
User avatar
Harlem9191
Top Poster
Top Poster
Posts: 87
Joined: Mon Jan 18, 2010 8:45 pm

Re: Software Installer
Harlem9191
That's a great tutorial.
I opted to create my own installer a while ago and I have something like the above however I have not yet found out how to properly fully install programs. The code I have done and the code provided do not add the program to the 'installed programs' list where you can add/remove/repair them. I'm guessing I'll have to find out how to edit the registry again which I am hoping I don't have to do. Do you know any methods of doing this code 'n' stuff.
I appreciate any such help.
28 posts Page 1 of 3
Return to “Tutorials”