Post by PackHack on Jan 11, 2015 3:43:23 GMT
Things you need:
1) A webhost. Free ones are perfect as all you need it for is to host 2 text files directly. I use www.x10hosting.com its free and simple to sign up on.
2) VisualBasic Express 2010 or any version really. I just prefer 2010, or 2013
Now I am going to try to quickly as I can explain how my updater works.() The updater finds the the current version(Version of program on the computer) from a text document(Version.txt) that your program creates with only the number of the version of the program. Your program will update this Version.txt with it's version every time it runs, The updater stores the current version as a variable for later use. Then the updater finds the Newest Version(The most recent version you have for download) from a text file(Ver.txt) hosted online(That is why you need #1 in 'Things you need') Ver.txt only contains the newest version number and the updater gets that number and stores it as another variable. Now that is has both the current version and the newest version when the user clicks the update button in the Updater. Once the button is clicked it will go through a If statement comparing the versions. It checks if the Newest is Greater than the Current number and if it is it continues with the update process and if isn't it displays a messagebox pops up telling the user that no update is needed. So that is in as short as I can make it explanation of what My updater does. On with the tutorial on how to make it.
First I'm going to tell you how I include the Updater in a program. Now I'm Just going to make it a simple form with nothing(Edit: simply just added a label to let me know what its doing, you will see a pic and see it in the code) but the update code, just using it as a example on how to use the updater in your program. There are also plenty of other ways to include it, just play around with it if you want this is just how I do it.
Pic:
You can also view this code with highlighted syntax at pastebin: pastebin.com/ZRn5E3tH
Imports System.IO
Public Class Form1
'These Subs are used in the program that the Updater will be Updating
Public Shared MyVersion As String = 1 'The version of the program, Used to detect either to update or not in the Updater exe
Public Shared Dir As String = Directory.GetCurrentDirectory() 'Variable storing the current directory
Sub UpdateMe()
'Button to close program and launch the updater
Application.DoEvents()
Label1.Text = "opening updater"
MessageBox.Show("This program will now close and launch the Updater")
Process.Start(Dir + "\Update.exe")
Me.Close()
End Sub
Public Sub VersionTextFile()
'Checks if the program needs to Create Version.txt
'or if it already exists and it can continue to
'write the version number to the text file
Application.DoEvents()
Dim FILE_NAME As String = Dir + "\Version.txt"
If System.IO.File.Exists(FILE_NAME) = True Then
Label1.Text = "txt file exists"
Application.DoEvents()
Label1.Text = "Carry on sir"
WriteVersionText()
Else
Application.DoEvents()
Label1.Text = "no txt file there"
File.Create(FILE_NAME).Dispose()
Label1.Text = "now there is"
WriteVersionText()
End If
End Sub
Public Sub AdminCheck()
'I include this in my program for 2 reasons, some
'of the Functions it has require admin and so
'no matter where the program is located it will
'still be able to write the text file
Application.DoEvents()
If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
Label1.Text = "Admin Check Finished"
Else
MsgBox("Must Run Program As Admin To Run Properly")
Me.Close()
End If
End Sub
Public Sub WriteVersionText()
'This simply writes the version number to the text file
Application.DoEvents()
Label1.Text = "Writing Version"
Dim objReader As StreamWriter
objReader = New StreamWriter(Dir + "\Version.txt")
objReader.Write(MyVersion)
objReader.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AdminCheck()
VersionTextFile()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class
Next is the updater itself,
Here is a list of everything you need in the form, some things need names, and it has to be put in certain places for it to look right, bellow you can see a example on how everything is:
4 Labels
1 listbox
1 Textbox
1 Button
and here is the pic containing the positions & names of everything you need, basically a diagram or whatever for the Updater:
And here is the code:
or highlighted syntax pastebin post: pastebin.com/EJg4TQk7
Imports System.IO
Imports System.Net
Public Class Form1
Private WithEvents httpclient As WebClient
'Variable Containing The Current Directory
Public Shared Dir As String = Directory.GetCurrentDirectory()
'Variable Containing The Directory To Version.txt
Public Shared VerDir As String = (Dir + "\Version.txt")
'Variable For Storing The Current Version
Public Shared Version As String = 0
'Variable For Storing The NewestVersion
Public Shared NewVersion As Integer = 0
'Variable For The .exe That Gets Updated, You Can Make This Changable
'By Loading A Text File Online With The Exe's Name, Just like
'We Do To Get The Download URL And The Newest Version
Public Shared CurrentEXEs As String = "SuicideBooter.exe"
'Variable For The URL With The Newest Version Linking The Text File(Needs to Be Direct)
Public Shared VerAddress As String = "http://gethelp.x10host.com/Ver.txt"
'Variable For The URL With The Download URL Linking The Text File(Needs to Be Direct)
Public Shared UpdateDL As String = "http://gethelp.x10host.com/UpdateDL.txt"
'Variable For Storing The Update URL
Public Shared UpdateURL As String = " "
'Variable For Retrieving The Newest Version
Public Shared ReturnValue As String = " "
'Variable For A WebClient
Public Shared instance As WebClient = New WebClient
Sub UpdateMe()
CheckVer()
Updater()
End Sub
Public Sub AdminCheck()
'I use this for the same reasons I use it in the program part
If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
Else
MsgBox("Must Run Program As Admin To Run Properly")
Me.Close()
End If
End Sub
Sub Updater()
'This sub determines if a update is required or not
Dim V1 As Integer
Dim V2 As Integer
V1 = Version
V2 = NewVersion
'Checking if the newest version is greater than the current version
If V2 > V1 Then
'If it is greater the program will show a message box then continue the update process
MessageBox.Show("Update Required")
GetUpdate()
ClearDir()
DownloadUpdate()
Else
'if it isnt greater the program will show a message box telling the user no update is needed
MessageBox.Show("No updating needed, You already have version: " + Version + " Which is the newest version released.")
End If
End Sub
Sub GetVer()
'This sub will get the current version from Version.txt
Application.DoEvents()
'Checking if Version.txt exists
If My.Computer.FileSystem.FileExists(VerDir) Then
Dim lines() As String = IO.File.ReadAllLines(VerDir)
VerB.Items.AddRange(lines)
Version = VerB.Items(0)
One.Text = VerB.Items(0)
Else
'if it doesn't exists a message box will appear telling the user to run the program at least
'once before trying to update
MessageBox.Show("Version file not found please run SuicideBooter at least once before updating!")
End If
End Sub
Sub UpdateMsgBox()
MessageBox.Show("After pressing the 'OK' button the Update process will start, Please be patient and allow 2-3 mins to finish")
End Sub
Sub CheckVer()
'This sub gets the newest version from the online host (Ver.txt)
Application.DoEvents()
Dim instance As WebClient = New WebClient
Dim address As String = VerAddress
Dim returnValue As String
'Changes the returnValue variable to the newest version
returnValue = instance.DownloadString(address)
'uses that variable to set the NewVersion variable and Two.Text And Change the StatusT.Text
NewVersion = returnValue
Two.Text = returnValue
StatusT.Text = ("New Version= " + returnValue)
Refresh()
End Sub
Sub GetDLURL()
'This Sub Grabs The Download URM from the online host (UpdateDL.txt)
Application.DoEvents()
Dim instance As WebClient = New WebClient
Dim address As String = UpdateDL
Dim returnValue As String
returnValue = instance.DownloadString(address)
'Uses the returnValue variable to Change the UpdateURL Variable to The Download link
UpdateURL = returnValue
StatusT.Text = ("Downloading Update From " + returnValue)
Refresh()
End Sub
Sub DLUpdate()
'This simply just downloads the program, and puts in in the current directory and rename it
Application.DoEvents()
My.Computer.Network.DownloadFile(UpdateURL, (Dir + "\SuicideBooter.exe"))
End Sub
Sub DownloadUpdate()
GetDLURL()
DLUpdate()
UpdateFinished()
End Sub
Sub UpdateFinished()
'Just displays a message box letting user know update is finished
MessageBox.Show("Update Finished, You may now run SuicideBooter!")
End Sub
Sub GetUpdate()
UpdateMsgBox()
End Sub
Sub ClearDir()
'This deletes the Files that are being updated from Directory to allow updating
Dim File1 As String
Dim File2 As String
File1 = (Dir + "\SuicideBooter.exe")
File2 = (Dir + "\Version.txt")
If System.IO.File.Exists(File1) = True Then
System.IO.File.Delete(File1)
End If
If System.IO.File.Exists(File2) = True Then
System.IO.File.Delete(File2)
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AdminCheck()
GetVer()
CheckVer()
End Sub
#Region "Form Buttons"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
UpdateMe()
End Sub
#End Region
End Class
And you can easily play around with the code to make it more suitable to your needs. Hope you guys find this useful.