This is my Code for Visual Basics 2010:
make a new project and add this code:
Code:
Public Class myupdater
Dim Web As New System.Net.WebClient
Dim EnteredSerial As String
Dim newVersion As String = ""
Dim Retry As Integer
Private Sub myupdater_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim myVersion As String
myVersion = My.Computer.FileSystem.ReadAllText("C:\mypath\version.txt")
''
newVersion = Web.DownloadString("http://my.url/version.txt")
If Not newVersion.Contains(myVersion) Then
Label1.ForeColor = Color.Red
Label1.Text = "Updating."
If My.Computer.FileSystem.DirectoryExists("C:\mypath\") Then
If My.Computer.FileSystem.FileExists("C:\mypath\my_Tool.exe") Then
IO.File.Delete("C:\mypath\my_Tool.exe")
My.Computer.Network.DownloadFile("http://my.url/my_Tool.exe", "C:\mypath\my_Tool.exe")
'System.Diagnostics.Process.Start("C:\mypath\my_Tool.exe")
Else
My.Computer.Network.DownloadFile("http://my.url/my_Tool.exe", "C:\mypath\my_Tool.exe")
'System.Diagnostics.Process.Start("C:\mypath\my_Tool.exe")
End If
If My.Computer.FileSystem.FileExists("C:\mypath\version.txt") Then
IO.File.Delete("C:\mypath\version.txt")
My.Computer.Network.DownloadFile("http://my.url/version.txt", "C:\mypath\version.txt")
'System.Diagnostics.Process.Start("C:\mypath\my_Tool.exe")
Else
My.Computer.Network.DownloadFile("http://my.url/version.txt", "C:\mypath\version.txt")
'System.Diagnostics.Process.Start("C:\mypath\my_Tool.exe")
End If
Else
My.Computer.FileSystem.CreateDirectory("C:\mypath\")
My.Computer.Network.DownloadFile("http://my.url/my_Tool.exe", "C:\mypath\my_Tool.exe")
My.Computer.Network.DownloadFile("http://my.url/version.txt", "C:\mypath\version.txt")
'System.Diagnostics.Process.Start("C:\mypath\my_Tool.exe")
End If
System.Diagnostics.Process.Start("C:\mypath\my_Tool.exe")
Me.Close()
Else
System.Diagnostics.Process.Start("C:\mypath\my_Tool.exe")
'newVersion.Show()
Me.Close()
End If
Catch Ex As Exception
MsgBox("Ein Fehler ist aufgetreten:" & vbCrLf & Ex.Message)
End Try
End Sub
End Class
Then add this to your main programm:
Under your "Public Class"
Code:
Dim Web As New System.Net.WebClient
Dim EnteredSerial As String
Dim newVersion As String = ""
Dim Retry As Integer
Into your Form1_load:
Code:
Try
Dim myVersion As String
myVersion = My.Computer.FileSystem.ReadAllText("C:\mypath\version.txt")
''
newVersion = Web.DownloadString("http://my.url/version.txt")
If Not newVersion.Contains(myVersion) Then
msgBox("A newer Version is available, the Programm will close now.")
System.Diagnostics.Process.Start("C:\mypath\Updater.exe")
End
End if
End Try
You just have to change the paths, names, etc.. to yours.
And you have to add a Label.
/done