Software Installer
Posted: Sat Mar 13, 2010 11:44 am
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":
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:
Now inside your "Button1_Click" event add this code:
Then still in the "Button1_Click" event add this code aswell:
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
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: Happy coding cooll;
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
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.Public InstallFolder = "My Application"
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
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. 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
Now inside your "Button1_Click" event add this code:
Code: Select all
That code will create our application folder inside the windows "Program Files" directory, again just like any other installer.My.Computer.FileSystem.CreateDirectory(My.Computer.FileSystem.SpecialDirectories.ProgramFiles & "\" & InstallFolder & "\")
Then still in the "Button1_Click" event add this code aswell:
Code: Select all
This code loops through all of our resource files and extracts them one at a time using our function which we added earlier.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
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:

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:

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

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: Happy coding cooll;