Jump to content

cbox


How Do You Auto update in vb 08?


Recommended Posts

Posted (edited)

How Do You Auto update in vb 08?

is it This?

 

 

 

 

Imports System.IO
Imports System.Net
Module Main
   Public Sub Main()
       Dim ExeFile As String ' the program that called the auto update
       Dim RemoteUri As String ' the web location of the files
       Dim Files() As String ' the list of files to be updated
       Dim Key As String ' the key used by the program when called back 
       ' to know that the program was launched by the 
       ' Auto Update program
       Dim CommandLine As String ' the command line passed to the original 
       ' program if is the case
       Dim myWebClient As New WebClient ' the web client
       Try
           ' Get the parameters sent by the application
           Dim param() As String = Split(Microsoft.VisualBasic.Command(), "|")
           ExeFile = param(0)
           RemoteUri = param(1)
           ' the files to be updated should be separeted by "?"
           Files = Split(param(2), "?")
           Key = param(3)
           CommandLine = param(4)
       Catch ex As Exception
           ' if the parameters wasn't right just terminate the program
           ' this will happen if the program wasn't called by the system 
           ' to be updated
           Exit Sub
       End Try
       Try
           ' Process each file 
           For i As Integer = 0 To Files.Length - 1
               Try
                   ' try to rename the current file before download the new one
                   ' this is a good procedure since the file can be in use
                   File.Move(Application.StartupPath & "\" & Files(i), _
                       Application.StartupPath & "\" & _
                       Now.TimeOfDay.TotalMilliseconds & ".old")
               Catch ex As Exception
               End Try
               ' download the new version
               myWebClient.DownloadFile(RemoteUri & Files(i), _
                   Application.StartupPath & "\" & Files(i))
           Next
           ' Call back the system with the original command line 
           ' with the key at the end
           System.Diagnostics.Process.Start(ExeFile, CommandLine & Key)
           ' do some clean up -  delete all .old files (if possible) 
           ' in the current directory
           ' if some file stays it will be cleaned next time
           Dim S As String = Dir(Application.StartupPath & "\*.old")
           Do While S <> ""
               Try
                   File.Delete(Application.StartupPath & "\" & S)
               Catch ex As Exception
               End Try
               S = Dir()
           Loop
       Catch ex As Exception
           ' something went wrong... 
           MsgBox("There was a problem runing the Auto Update." & vbCr & _
               "Please Contact Admin at MMG.com" & vbCr & ex.Message, _
               MsgBoxStyle.Critical)
       End Try
   End Sub
End Module
Public Class Form4
   Public Class AutoUpdate
       Public Function AutoUpdate(ByRef CommandLine As String) As Boolean
           Dim Key As String = "&**#@!" ' any unique sequence of characters
           ' the file with the update information
           Dim sfile As String = "update.dat"
           ' the Assembly name 
           Dim AssemblyName As String = _
                   System.Reflection.Assembly.GetEntryAssembly.GetName.Name
           ' here you need to change the web address 
           Dim RemotePath As String = _
               "http://MasterModdingGroupMMGD.weebly.com/"
           ' where are the files for a specific system
           Dim RemoteUri As String = RemotePath & AssemblyName & "/"
           ' clean up the command line getting rid of the key
           CommandLine = Replace(Microsoft.VisualBasic.Command(), Key, "")
           ' Verify if was called by the autoupdate
           If InStr(Microsoft.VisualBasic.Command(), Key) > 0 Then
               Try
                   ' try to delete the AutoUpdate program, 
                   ' since it is not needed anymore
                   System.IO.File.Delete(Application.StartupPath & "\autoupdate.exe")
               Catch ex As Exception
               End Try
               ' return false means that no update is needed
               Return False
           Else
               ' was called by the user
               Dim ret As Boolean = False ' Default - no update needed
               Try
                   Dim myWebClient As New System.Net.WebClient 'the webclient
                   ' Download the update info file to the memory, 
                   ' read and close the stream
                   Dim file As New System.IO.StreamReader( _
                       myWebClient.OpenRead(RemoteUri & sfile))
                   Dim Contents As String = file.ReadToEnd()
                   file.Close()
                   ' if something was read
                   If Contents <> "" Then
                       ' Break the contents 
                       Dim x() As String = Split(Contents, "|")
                       ' the first parameter is the version. if it's 
                       ' greater then the current version starts the 
                       ' update process
                       If x(0) > Application.ProductVersion Then
                           ' assembly the parameter to be passed to the auto 
                           ' update program
                           ' x(1) is the files that need to be 
                           ' updated separated by "?"
                           Dim arg As String = Application.ExecutablePath & "|" & _
                                       RemoteUri & "|" & x(1) & "|" & Key & "|" & _
                                       Microsoft.VisualBasic.Command()
                           ' Download the auto update program to the application 
                           ' path, so you always have the last version runing
                           myWebClient.DownloadFile(RemotePath & "autoupdate.exe", _
                               Application.StartupPath & "\autoupdate.exe")
                           ' Call the auto update program with all the parameters
                           System.Diagnostics.Process.Start( _
                               Application.StartupPath & "\autoupdate.exe", arg)
                           ' return true - auto update in progress
                           ret = True
                       End If
                   End If
               Catch ex As Exception
                   ' if there is an error return true, 
                   ' what means that the application
                   ' should be closed
                   ret = True
                   ' something went wrong...
                   MsgBox("There was a problem runing the Auto Update." & vbCr & _
                       "Please Contact Admin:mastermoddinggroup.weebly.com" & vbCr & ex.Message, _
                       MsgBoxStyle.Critical)
               End Try
               Return ret
           End If
       End Function
   End Class

Edited by yoda302055
  • Like 1
Posted

You need a server, or some place to host direct links to files.

 

Upload on your server a text file and put the name of the current version in it. When you build your project, use like My.Settings.Version and set it as 1.0.0.0, and upgrade it as 1.0.0.1 etc.

 

So then

if (My.Settings.Version == web.DownloadString(url to txt file)
  open up a connection and download the file, then do
 like a new process, and set it to that downloaded file and run it

 

I assume you just needed the "spring board" for the idea. I was the same way, till someone told me that. Its quite easy to code, once you get better you can include an XML file and use the XML class to read specific stuff from your xml file.

  • 5 months later...
Posted (edited)

You need a server, or some place to host direct links to files.

 

Upload on your server a text file and put the name of the current version in it. When you build your project, use like My.Settings.Version and set it as 1.0.0.0, and upgrade it as 1.0.0.1 etc.

 

So then

if (My.Settings.Version == web.DownloadString(url to txt file)
  open up a connection and download the file, then do
 like a new process, and set it to that downloaded file and run it

 

I assume you just needed the "spring board" for the idea. I was the same way, till someone told me that. Its quite easy to code, once you get better you can include an XML file and use the XML class to read specific stuff from your xml file.

I forgot About This, Thanks

Edited by yoda302055

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...