School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,150 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,701 people online right now. Registration is fast and FREE... Join Now!




Very simple updater

 
Reply to this topicStart new topic

> Very simple updater, download update instal the new updates and restart main program

NoBrain
Group Icon



post 15 Oct, 2009 - 04:29 AM
Post #1


smile.gif

so i will show you how to make UpDater to your Program smile.gif

The main program use to download the updates and the second to make the needed updates and restart the main program



lets begin place button Update and Inet control (you need component-> Mircrosoft Internet Control 6.0 (or "C:\Windows\system32\MSINET.OCX")

Make your Inet control propery "Protocol" to "4-icHTTP"

So now you have all your controls in place lets code smile.gif

So hiting button Update will beging down loading from the URL you have enter and begin downloading in specify location to do this we make the variables

FileName the name of the file you want to download
URLName the http server where you got the file
FileToGet it is the url and filename combine in one


then a second program will start but first next download our new version

so lets begin

we will fill our variables with the specf. name and url and download the file.
all will do our Inet Control the function "Execute" do all thing.

here is description of that function :

Sub Execute([URL], [Operation], [InputData], [InputHdrs])
Member of InetCtlsObjects.Inet
Issue a request to the remote computer

Then we use the Shell to start our updater

for that we need the varialbe for our updater path

FilePth is used for that here is where our Updater path is containt, we add at the end and our file name as well

so the code

CODE

Private Sub cmdUpdate_Click()
On Error GoTo err_hndl

Dim FileName As String ' Contain the file name
Dim URLName As String 'Contain the URL for our http server
Dim FileToGet As String ' Used to combine urlname and filename variable
Dim FilePth As String ' The path to our updater
Dim Process As Long

' Downloading the file

    FileName = "Place your file name here (example: test.txt)"
    URLName = "Place your URL here (example: http://myurlspace.com/)"
    FileToGet = URLName & FileName
    
    Inet1.Execute FileToGet, "GET " & Chr(34) & App.Path & "\" & FileName & Chr(34)

' File is downloaded and the updater is started    
    FilePth = "C:\Documents and Settings\Raziel\Desktop\me Tutorials\DIC\Updated Program\Updater\"
    FilePth = FilePth & "MeUpdt.exe"

    Process = Shell(FilePth, vbNormalNoFocus)
' Close the program
    End
    Exit Sub
err_hndl:
    MsgBox Err.Description, vbCritical


End Sub


So for now we download the file to update and we start our updater

Now for the Updater Program

Make new project on VB6

Add reference "Microsoft Scripting Runtime" or From Browse button add "C:\WINDOWS\system32\scrrun.dll"

so we make few variables as well smile.gif

NewFile As String is used to show the location of the new version of the file that we want to update
PathToCopy As String is used to location where we want to put it in our main program
Process As Long is used to open the process of our main program
StartingPrgrm As String is used to show the location of the exe of our main program so we can start it again

so we use "Microsoft Scripting Runtime" to copy the the the new location then we start our main program and end the updater


so here is the code

CODE

Private Sub Form_Load()
On Error GoTo err_hndl
    Me.Visible = False
    Dim NewFile As String
    Dim PathToCopy As String
    Dim StartingPrgrm As String
    Dim Process As Long
    
    NewFile = "The path and the name of the file you want to copy example "C:\test.txt""
    PathToCopy = "The path where you want to copy the file example : "C:\MyProgram\""
    
    With New FileSystemObject
        .CopyFile NewFile, PathToCopy
    End With
    
    StartingPrgrm = "The path of your main program example "C:\MyProgra\""
    StartingPrgrm = StartingPrgrm & "MyExe.exe"
    
    Process = Shell(StartingPrgrm, vbNormalFocus)
    End
    Exit Sub
err_hndl:
    MsgBox Err.Description, vbCritical
    End
End Sub


WARNING: This Updater will not work on updating exe of your main program. Make a Delay in updater to wait your main program is closed!!!!!!

Hope you find it useful

This post has been edited by NoBrain: 15 Oct, 2009 - 01:48 PM
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

NoBrain
Group Icon



post 15 Oct, 2009 - 03:14 PM
Post #2
so here is an update of a sort to the updater

the updater download the file and copy it to the spec location

the main program only run the updater and close it self. then updater do all the things

so in the button update in our main program we start the updater and end the main program.

so here is the code

CODE

Private Sub cmdUpdate_Click()
    Dim process As Long
        process = Shell(FilePth, vbNormalNoFocus)
        End
End Sub


so now we start the updater.

here is the function that download the file.

CODE

Private Function DownLoadUPDate() As Boolean
    On Error GoTo err_hnld
    Dim FileName As String ' Contain the file name
    Dim URLName As String 'Contain the URL for our http server
    Dim FileToGet As String ' Used to combine urlname and filename variable
        
        ' Downloading the file

        FileName = "Place your file name here (example: test.txt)"
        URLName = "Place your URL here (example: http://myurlspace.com/)"
        FileToGet = URLName & FileName
        
        Inet1.Execute FileToGet, "GET " & Chr(34) & App.Path & "\" & FileName & Chr(34)

        ' File is downloaded and we return true
        
        DownLoadUPDate = True
    Exit Function
    
err_hnld:
    DownLoadUPDate = False
End Function

this function is put in your Updater project you will need to place Inet control there and make the configuration of

his propertys.

so here is the new code for your updater


CODE


Private Sub Form_Load()
On Error GoTo err_hndl

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' put delay here if you want to update the exe of your main program !!!
' make it to wait till your main program is closed
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If DownLoadUPDate = True Then
    Me.Visible = False
    Dim NewFile As String
    Dim PathToCopy As String
    Dim StartingPrgrm As String
    Dim Process As Long
    
    NewFile = App.Path & "\Test.txt"
    Debug.Print NewFile
    PathToCopy = "C:\Documents and Settings\Raziel\Desktop\me Tutorials\DIC\Updated Program\"
    
    With New FileSystemObject
        .CopyFile NewFile, PathToCopy
    End With
    
    StartingPrgrm = "C:\Documents and Settings\Raziel\Desktop\me Tutorials\DIC\Updated Program\"
    StartingPrgrm = StartingPrgrm & "MyExe.exe"
    
    Process = Shell(StartingPrgrm, vbNormalFocus)
    End
Else
    MsgBox "Error Downloading file", vbCritical
End If
End
err_hndl:
    MsgBox Err.Description, vbCritical
    End
End Sub


Private Function DownLoadUPDate() As Boolean
    On Error GoTo err_hnld
    Dim FileName As String ' Contain the file name
    Dim URLName As String 'Contain the URL for our http server
    Dim FileToGet As String ' Used to combine urlname and filename variable
    Dim FilePth As String ' The path to our updater
        
        ' Downloading the file

        FileName = "Place your file name here (example: test.txt)"
        URLName = "Place your URL here (example: http://myurlspace.com/)"
        FileToGet = URLName & FileName
        
        Inet1.Execute FileToGet, "GET " & Chr(34) & App.Path & "\" & FileName & Chr(34)

        ' File is downloaded and we return true
        
        DownLoadUPDate = True
    Exit Function
    
err_hnld:
    DownLoadUPDate = False
End Function


it is kinda new version tongue.gif

i Hope i dont break some rule :S

feel free to modify it smile.gif

EDIT:

http://stackoverflow.com/questions/95112/h...isual-basic-vb6

use sleep for delay if you want to update the exe of your main program

This post has been edited by NoBrain: 15 Oct, 2009 - 03:34 PM
Go to the top of the page
+Quote Post


Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 04:33PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month