Page 1 of 1

Very simple updater download update instal the new updates and restart main program Rate Topic: -----

#1 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Posted 15 October 2009 - 05:29 AM

:)

so i will show you how to make UpDater to your Program :)

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 :)

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

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 :)

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

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 October 2009 - 02:48 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Very simple updater

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Posted 15 October 2009 - 04:14 PM

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

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.

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



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 :P

i Hope i dont break some rule :S

feel free to modify it :)

EDIT:

http://stackoverflow...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 October 2009 - 04:34 PM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1