Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[TUT] Real Update System (auto-check, auto-install)

Hey everybody !

I've seen a lot of people that asked for an update system... I've seen some system, but not really working... So I give you mine :) It's not optimized, so if you have comment, please post ! :)

So here is the tut :

First, I explain you how it works : The system check the content of a file that is in your database : the number of your new version. If this number isn't equal as the version of the program, it opens the update form. In this form, there is a button, that when you click on it, save the content of the file where is saved the number of the newest version, and download it in your server. So you have to name your newest version same as the number that is in the file on your server ! After that, it UnRAR it, and install it...

Code for your main form, that check updates :

Code
Public Sub check_update()
  Dim webResponse3 As System.Net.HttpWebResponse = Nothing
  Dim webRequest3 As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http:/www.example.com/the_file_where_is_saved_the_number_of_your_newest_version.html")
  Try
    webResponse3 = DirectCast(webRequest3.GetResponse(), System.Net.HttpWebResponse)
    Dim srResp As System.IO.StreamReader
    srResp = New System.IO.StreamReader(webResponse3.GetResponseStream())
    Dim last_version As String
    last_version = srResp.ReadToEnd
    If Not derniere_version = "number version, like 1.2.2" Then
    Me.Hide()
    update.Show()
    Me.Close()
    Else
    OtherForm.Show()
    End If
  Catch ex As Exception
    MsgBox("Erreur while verifying update...")
    OtherForm.Show()
  End Try

    End Sub

Code for your update form, that download and instal update (you need UnRAR.exe in the same folder of your app ! download : here):

Code
Public last_version as string

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  check_version()
  If Not Dir("update.rar") = "" Then
    Kill("update.rar")
  End If

  If My.Computer.Network.IsAvailable Then
    Dim newfile As String = "update.rar"
    Try
    MsgBox("Download will start. If application freeze, don't worry, it's normal !")
    My.Computer.Network.DownloadFile("http://www.frag-n-roses.com/downloads/Release v" & last_version & ".rar", newfile)
    MsgBox("Download finished !" & vbCrLf & "Please wait while update system unzip updated program...")
    UnRAR(".\update.rar", ".\")
    Catch
    MsgBox("Error while downloading !")
    End Try
  Else
    MsgBox("You're NOT connected to internet ! Please check your connect...")
  End If
    End Sub

Public Sub check_version()
  Dim webResponse3 As System.Net.HttpWebResponse = Nothing
  Dim webRequest3 As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http:/www.example.com/the_file_where_is_saved_the_number_of_your_newest_version.html")
  Try
    webResponse3 = DirectCast(webRequest3.GetResponse(), System.Net.HttpWebResponse)
    Dim srResp As System.IO.StreamReader
    srResp = New System.IO.StreamReader(webResponse3.GetResponseStream())
    last_version = srResp.ReadToEnd
  Catch ex As Exception

  End Try

    End Sub

Private Function UnRAR(ByVal FileName As String, ByVal ExtractDir As String) As Boolean
  Dim Success As Boolean = False
  Dim CodeDeSorti As Integer

  Try
    Dim proc As New Process()
    With proc
    With .StartInfo
    .UseShellExecute = False
#If DEBUG Then
    .FileName = "UnRAR.exe"
#Else
    .FileName = My.Application.Info.DirectoryPath & "UnRAR.exe"
#End If
    .Arguments = " x -ibck -inul -or -y " & " """ & FileName & """  """ & ExtractDir & """"
    .WorkingDirectory = ExtractDir
    .WindowStyle = ProcessWindowStyle.Hidden
    .CreateNoWindow = True
    End With
    .Start()
    .WaitForExit()
    CodeDeSorti = .ExitCode
    .Close()
    End With
    If CodeDeSorti < 2 Then
    Success = True
    End If
  Catch ex As Exception
    MsgBox("UpDate system can't install updated program... Please do it yourself !" & vbCrLf & vbCrLf & "Program will close when you'll press OK...)")
  End Try

  Return Success
    End Function

Hope it will help you...

PS: Sorry if there are any french languages, I'm french :p
Bump ! It's not helping ??
Good, but there is a lot of source like that, but thank's you :D
(Feb 19, 2011 04:04 AM)E.T Wrote:  Good, but there is a lot of source like that, but thank's you :D

Thanks for reply :)

i know there are a lot of source like that, but it's not the same system, and they haven't the code for extract a *.rar archive :)
(Feb 19, 2011 04:04 AM)E.T Wrote:  Good, but there is a lot of source like that, but thank's you :D

Well, its the first time i see an example with webrequest...
Here all snippets are like download & run .

The fact that it uses UnRar put me off.
(Feb 19, 2011 06:39 AM)xCocaine Wrote:  Well, its the first time i see an example with webrequest...
Here all snippets are like download & run .

Thanks !

(Feb 19, 2011 09:06 AM)This Girl Is On Fire Wrote:  The fact that it uses UnRar put me off.

It uses UnRAR just because it's an example of how to auto-install an archive !
xSilent has a better tutorial on this, maybe you can watch his videos and improve your code.
His tut doesn't show how to Unrar... It's a simple tut to show a method... you can improve it like you want, but it works fine for me
The Alliance
Ok guys i think this cant work since when it needs to extract update into a startup folder it will show error:
file is already in use this only can work if you make 2 projects and you use process.start (application) and process.start (update) when update is closing you need to call this command process.start (application.exe) and me.close...

I think thats only solution or you can change name of application i think that will work too but i dont guess anything...
This code has been posted on multiple websites. Example:
http://www.vbforums.com/showthread.php?t=643189

Quit leeching please...
Close this thread, cz this thread is gonna flame of fire,and flame of users xD
I have tried this, but it cant simply compare the .txt file on the server to a label. It just does the code that comes before the "else". Like it cant compare the two strings correctly and tell that they are not equal to eachother. Anyone know what might be going wrong?


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by AspectModdingMay 29, 2016 08:48 AM 3 166 May 29, 2016 08:48 AM
Last Post: severos
[.NET] by master4allOct 13, 2012 05:24 PM 8 444 Oct 13, 2012 05:24 PM
Last Post: Ashes
[.NET] by PsychotiicAug 2, 2012 01:22 PM 22 869 Aug 2, 2012 01:22 PM
Last Post: ident