[VB.net]Auto Update, Auto Delete, Kill Same Process. Force Delete&Update. - Onin42 - Mar 26, 2012
Auto Update
Hi, i made this a long time ago. So i though of sharing it, Since i never found it anywhere.
My webhost was SPAM who don't let you have .txt and .exe files.
So i was obligated to use .html (for the .txt and more used) and .zip(which i descompact later) files.
This snippet can Kill Process, Auto update, Check for Updates, Auto Delete, ... hidden.
I'm bad at explications. so just give a test to the code.
For use just add the module to your project.
cl_update.KillPro(My.Application.Info.Title)
cl_update.NewUpdateHtml() 'True or false for Show the MsgBoxs
Code:
Code Imports Shell32 'Add always reference for Microsoft Shell and Automation
Imports System.Net, System.IO
Public Module cl_update
Public Sub KillPro(ByRef strProcessToKill As String)
Dim proc() As Process = Process.GetProcesses
Dim proDate As Date = Process.GetCurrentProcess.StartTime
For i As Integer = 0 To proc.GetUpperBound(0)
If proc(i).ProcessName = strProcessToKill And proc(i).StartTime > proDate Then
Dim msgx As Object = MsgBox("Another " & My.Application.Info.Title & " is currently executed," & vbCrLf & "Do you want to stop it?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "AutoUpdate")
If msgx = vbYes Then
proc(i).Kill()
'Else : End
End If
End If
Next
End Sub
Public Sub NewUpdateHtml(Optional ByVal CheckUpdate As Boolean = False)
Try
If My.Computer.Network.IsAvailable Then
'see new version in html (Because of webhost000 who don't accept .txt files and .exe files)
Dim Link As String = "http://www.YourSite.com/Execution/" & My.Application.Info.Title & "/version.html"
Dim wRequest As WebRequest = WebRequest.Create(Link)
Dim wResult As WebResponse = wRequest.GetResponse()
Dim sReader As New StreamReader(wResult.GetResponseStream())
Dim SourceCode As String = sReader.ReadToEnd()
sReader.Close()
wResult.Close()
'remove all the data for see just the new version
SourceCode = Split(SourceCode, "<h1>")(1)
SourceCode = Split(SourceCode, "</h1>")(0)
SourceCode = SourceCode.Trim
'choice: update or not
If Not SourceCode.Contains(" yx") Then
If (SourceCode.Replace(" o", "") <= My.Application.Info.Version.ToString) Then
If CheckUpdate = True Then MsgBox("You have the latest version of the software.", MsgBoxStyle.Information, "AutoUpdate")
Else
Dim msgx As Object = MsgBox("An update is available, do you want to dowload it?", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "Auto Update")
If msgx = vbYes Then
'go to update page
'System.Diagnostics.Process.Start("http://www.YourSite.com/Execution/" & My.Application.Info.Title & "/version.html")
'change name current software
If Not File.Exists(My.Application.Info.DirectoryPath & "\Old" & My.Application.Info.Title & ".exe") Then
File.Move(Application.ExecutablePath, My.Application.Info.DirectoryPath & "\Old" & My.Application.Info.Title & ".exe")
Else
File.Delete(My.Application.Info.DirectoryPath & "\Old" & My.Application.Info.Title & ".exe")
File.Move(Application.ExecutablePath, My.Application.Info.DirectoryPath & "\Old" & My.Application.Info.Title & ".exe")
End If
'download update zip (Because of webhost000 who don't accept .exe file)
If Not File.Exists(My.Application.Info.DirectoryPath & "\New " & My.Application.Info.Title & ".zip") Then
My.Computer.Network.DownloadFile("http://www.YourSite.com/Execution/" & My.Application.Info.Title & "/" & SourceCode.Replace(" o", "") & "/" & My.Application.Info.Title & ".zip", My.Application.Info.DirectoryPath & "\New " & My.Application.Info.Title & ".zip")
Else
File.Delete(My.Application.Info.DirectoryPath & "\New " & My.Application.Info.Title & ".zip")
My.Computer.Network.DownloadFile("http://www.YourSite.com/Execution/" & My.Application.Info.Title & "/" & SourceCode.Replace(" o", "") & "/" & My.Application.Info.Title & ".zip", My.Application.Info.DirectoryPath & "\New " & My.Application.Info.Title & ".zip")
End If
'decompact zip file (update)
DescompactZip(My.Application.Info.DirectoryPath & "\New " & My.Application.Info.Title & ".zip", My.Application.Info.DirectoryPath)
'delete zip file
My.Computer.FileSystem.DeleteFile(My.Application.Info.DirectoryPath & "\New " & My.Application.Info.Title & ".zip")
'create the bat for remove current software
AppendText(Environ("tmp") & "\Xupdate.bat", "echo off" & vbCrLf & ":Repeat " & vbCrLf & "del """ & My.Application.Info.DirectoryPath & "\Old" & My.Application.Info.Title & ".exe""" & vbCrLf & "if exist """ & My.Application.Info.DirectoryPath & "\Old" & My.Application.Info.Title & ".exe"" goto Repeat" & vbCrLf & "del """ & Environ("tmp") & "\Xupdate.bat""")
Interaction.Shell(Environ("tmp") & "\Xupdate.bat", AppWinStyle.Hide)
'run updated software
'Interaction.Shell(My.Application.Info.DirectoryPath & "\" & My.Application.Info.Title & ".exe", AppWinStyle.NormalFocus, False)
MsgBox("Updated Sucessfully", MsgBoxStyle.Information, "AutoUpdate")
Application.Exit()
Else
If SourceCode.Contains(" o") Then End
End If
End If
Else : AutoDelete()
End If
End If
Catch ex As Exception
MsgBox("Error come, Details:" & vbCrLf & ex.Message.ToString, MsgBoxStyle.Exclamation, "AutoUpdate")
Application.Exit()
End Try
End Sub
Private Sub AutoDelete()
If File.Exists(Environ("tmp") & "\Xdelete.bat") Then File.Delete(Environ("tmp") & "\Xdelete.bat")
AppendText(Environ("tmp") & "\Xdelete.bat", "echo off" & vbCrLf & ":Repeat " & vbCrLf & "del """ & Application.ExecutablePath & """" & vbCrLf & "if exist """ & Application.ExecutablePath & """ goto Repeat" & vbCrLf & "del """ & Environ("tmp") & "\Xdelete.bat""")
Interaction.Shell(Environ("tmp") & "\Xdelete.bat", AppWinStyle.Hide)
Application.Exit()
End Sub
Private Sub AppendText(ByVal vsFilePath As String, ByVal vsText As String)
With New System.IO.StreamWriter(vsFilePath, True)
.WriteLine(vsText)
.Close()
End With
End Sub
Private Sub DescompactZip(ByVal strSource As String, ByVal strDest As String)
Dim Sh As New Shell
Dim SF As Folder = Sh.NameSpace(strSource) 'Sh.NameSpace("C:\ZipFile.zip")
Dim DF As Folder = Sh.NameSpace(strDest) 'Sh.NameSpace("C:\Unzipped Files")
For Each F As FolderItem In SF.Items
DF.CopyHere(F)
Next
End Sub
End Module
* - SomeWhiteGuy - Mar 26, 2012
PHP Code
<?php Dim cV$ = "1.0" Dim wc As New WebClient() If wc.DownloadText("http://www.dropbox.com/version.txt") > cV Then wc.DownloadFile("http://www.dropbox.com/new.exe") Else MsgBox("Up to date!") End If
Done.
* - Onin42 - Mar 26, 2012
I was using this same code. but this seems a litle childesh to me, using dropbox.
I wanted to use a html page(for the users to download it and to get the version) and descompact all updates (if dll isues or else) auto deleting it's self.
Forcing auto delete or auto update of all programs who can reach the html file.
* - SomeWhiteGuy - Mar 26, 2012
(Mar 26, 2012 04:27 PM)Onin42 Wrote: I was using this same code. but this seems a litle childesh to me, using dropbox.
I wanted to use a html page(for the users to download it and to get the version) and descompact all updates (if dll isues or else) auto deleting it's self.
Forcing auto delete or auto update of all programs who can reach the html file.
You make a separate application for the updater and make your main application start it then close. If they're stupid enough to try and open the main application when it is updating then they deserve to get an error.
How is it childish using DropBox? One of the only file hosting websites where you can direct link without having to pay for a premium membership or some shit...and SPAM uses analytic scripts so if you don't disable them then you will download those also and that'll fuck you up pretty quick.
* - Onin42 - Mar 26, 2012
Quote:You make a separate application for the updater and make your main application start it then close. If they're stupid enough to try and open the main application when it is updating then they deserve to get an error.
This is why, this is an Auto Update, for the ones who need it, so they won't use more files than needed.
Quote:How is it childish using DropBox? One of the only file hosting websites where you can direct link without having to pay for a premium membership or some shit...and SPAM uses analytic scripts so if you don't disable them then you will download those also and that'll fuck you up pretty quick.
You are right, To easy to use, that's why it's childish, Sorry for my bad english.
I wanted a more complex and personal issue, using our own html file for the presentation, or else...
* - SomeWhiteGuy - Mar 26, 2012
(Mar 26, 2012 04:50 PM)Onin42 Wrote: This is why, this is an Auto Update, for the ones who need it, so they won't use more files than needed.
You are right, To easy to use, that's why it's childish, Sorry for my bad english.
I wanted a more complex and personal issue, using our own html file for the presentation, or else...
Why do something more difficult when you could do something easier that accomplishes the same thing without cutting corners?
Your logic is illogical.
* - 0xDEAD10CC - Mar 26, 2012
(Mar 26, 2012 12:56 PM)SomeWhiteGuy Wrote: PHP Code
<?php Dim cV$ = "1.0" Dim wc As New WebClient() If wc.DownloadText("http://www.dropbox.com/version.txt") > cV Then wc.DownloadFile("http://www.dropbox.com/new.exe") Else MsgBox("Up to date!") End If
Done.
You're implicitly converting your types in there though...
* - Coleak - Mar 26, 2012
(Mar 26, 2012 04:58 PM)SomeWhiteGuy Wrote: Why do something more difficult when you could do something easier that accomplishes the same thing without cutting corners?
Your logic is illogical.
The more code, the better. Logic at its finest.
* - (╯°□°)╯︵ ┻━━┻ - Mar 26, 2012
https://hackforums.net/showthread.php?tid=2228973
* - n0$f3ratu$ - Mar 27, 2012
(Mar 26, 2012 07:09 PM)(╯°□°)╯︵ ┻━━┻ Wrote: https://hackforums.net/showthread.php?tid=2228973
https://hackforums.net/showthread.php?tid=1231432
* - idb. - Mar 27, 2012
(Mar 26, 2012 12:56 PM)SomeWhiteGuy Wrote: PHP Code
<?php Dim cV$ = "1.0" Dim wc As New WebClient() If wc.DownloadText("http://www.dropbox.com/version.txt") > cV Then wc.DownloadFile("http://www.dropbox.com/new.exe") Else MsgBox("Up to date!") End If
Done.
Why exactly are you declaring the version number variable as a String instead of a Double and then comparing that String to another String trying to find out which numeric value is greater?
* - 0xDEAD10CC - Mar 27, 2012
(Mar 27, 2012 08:49 AM)idb Wrote: Why exactly are you declaring the version number variable as a String instead of a Double and then comparing that String to another String trying to find out which numeric value is greater?
That's what I had posted and wondered too lol: https://hackforums.net/showthread.php?tid=2340712&pid=21138922#pid21138922
* - SomeWhiteGuy - Mar 27, 2012
(Mar 27, 2012 08:49 AM)idb Wrote: Why exactly are you declaring the version number variable as a String instead of a Double and then comparing that String to another String trying to find out which numeric value is greater?
It was an example. I didn't understand why OP needed all of what he posted.
|