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

.NET 

[VB.net]Auto Update, Auto Delete, Kill Same Process. Force Delete&Update.

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
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.
Thread: Backend Web-Dev. - by SomeWhiteGuy

WATCH OUT 'LIL HOE,
MY PARTNA STILL SMOKE ON PAROLE
selling -
megabits.org + freakin.pro
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.
(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.
Thread: Backend Web-Dev. - by SomeWhiteGuy

WATCH OUT 'LIL HOE,
MY PARTNA STILL SMOKE ON PAROLE
selling -
megabits.org + freakin.pro
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...
(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.
Thread: Backend Web-Dev. - by SomeWhiteGuy

WATCH OUT 'LIL HOE,
MY PARTNA STILL SMOKE ON PAROLE
selling -
megabits.org + freakin.pro
(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...
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(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.
https://hackforums.net/showthread.php?tid=2228973
(Mar 26, 2012 07:09 PM)(╯°□°)╯︵ ┻━━┻ Wrote:  https://hackforums.net/showthread.php?tid=2228973

https://hackforums.net/showthread.php?tid=1231432
[Image: logo.gif]
(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?
Need a custom software? Check out my freelance service here! 6+ years and counting, never a complaint :)

STOP STEALING CODE.

FREE NATHAN

People who report posts are lamers.
(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?ti...id21138922
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(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.
Thread: Backend Web-Dev. - by SomeWhiteGuy

WATCH OUT 'LIL HOE,
MY PARTNA STILL SMOKE ON PAROLE
selling -
megabits.org + freakin.pro


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by gigajewNov 17, 2019 11:47 AM 17 1,547 Nov 17, 2019 11:47 AM
Last Post: gigajew
[.NET] by Formula 1Mar 3, 2019 02:36 PM 6 229 Mar 3, 2019 02:36 PM
Last Post: Formula 1
[C] by chrizatorJul 22, 2018 05:09 AM 4 229 Jul 22, 2018 05:09 AM
Last Post: Anzee