Vyriesil som to takto.
Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Const INTERNET_FLAG_EXISTING_CONNECT = &H20000000
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal lpszAgent As String, ByVal dwAccessType As Long, _
ByVal lpszProxyName As String, ByVal lpszProxyBypass As String, _
ByVal dwFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias _
"InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, _
ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As _
Long) As Integer
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As _
Long, ByVal lpBuffer As String, ByVal dwNumberOfBytesToRead As Long, _
lNumberOfBytesRead As Long) As Integer
' Download a file from Internet and save it to a local file
'
' it works with HTTP and FTP, but you must explicitly include
' the protocol name in the URL, as in
' CopyURLToFile "http://www.vb2themax.com/default.asp", "C:\vb2themax.htm"
Sub CopyURLToFile(ByVal URL As String, ByVal FileName As String)
Dim hInternetSession As Long
Dim hUrl As Long
Dim FileNum As Integer
Dim ok As Boolean
Dim NumberOfBytesRead As Long
Dim Buffer As String
Dim fileIsOpen As Boolean
On Error GoTo ErrorHandler
' check obvious syntax errors
If Len(URL) = 0 Or Len(FileName) = 0 Then err.Raise 5
' open an Internet session, and retrieve its handle
hInternetSession = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, vbNullString, 0)
If hInternetSession = 0 Then err.Raise vbObjectError + 1000, , _
"An error occurred calling InternetOpen function"
' open the file and retrieve its handle
hUrl = InternetOpenUrl(hInternetSession, URL, vbNullString, 0, _
INTERNET_FLAG_EXISTING_CONNECT, 0)
If hUrl = 0 Then err.Raise vbObjectError + 1000, , _
"An error occurred calling InternetOpenUrl function"
' ensure that there is no local file
On Error Resume Next
Kill FileName
On Error GoTo ErrorHandler
' open the local file
FileNum = FreeFile
Open FileName For Binary As FileNum
fileIsOpen = True
' prepare the receiving buffer
Buffer = Space(4096)
Do
' read a chunk of the file - returns True if no error
ok = InternetReadFile(hUrl, Buffer, Len(Buffer), NumberOfBytesRead)
' exit if error or no more data
If NumberOfBytesRead = 0 Or Not ok Then Exit Do
' save the data to the local file
Put #FileNum, , Left$(Buffer, NumberOfBytesRead)
Loop
' flow into the error handler
ErrorHandler:
' close the local file, if necessary
If fileIsOpen Then Close #FileNum
' close internet handles, if necessary
If hUrl Then InternetCloseHandle hUrl
If hInternetSession Then InternetCloseHandle hInternetSession
' report the error to the client, if there is one
If err Then err.Raise err.Number, , err.Description
End Sub
Private Sub Form_Load()
Update.Command1.Caption = "Skontroluj"
End Sub
Private Sub Command1_Click()
Dim FF As Integer
Dim Riadok As String
Dim Text_vystup As String
Dim datum1 As String
Dim datum2 As String
Update.Command1.Enabled = False
FF = FreeFile
CopyURLToFile "http://xx.xx.xx/xx/datum.txt", "data.dat"
Open "data.dat" For Input As FF
Text_vystup = Input(LOF(FF), #FF)
Label4.Caption = Text_vystup
datum1 = Text_vystup
Label5.Caption = FileDateTime(App.Path & "\xxx.exe") Subor na disku
datum2 = Label5
If datum1 > datum2 Then
Update.Label1.Caption = " Stahujem !"
Update.Label1.Visible = True
Form1.Image17.Visible = False
stiahny
Else
Update.Label1.Visible = True
Form1.Image17.Visible = False
End If
End Sub
Private Sub stiahny()
Inet1.AccessType = icUseDefault
'URL of FTP Site goes here.
Inet1.URL = "ftp://www.xxxxx.xx.xx"
Inet1.UserName = "xxx.xxxxx.xx.xx"
Inet1.Password = "xxxxxxxxx"
Inet1.RequestTimeout = 40
' GET Command here.
' download welcome.txt and place it on c:\welcome.txt
Inet1.Execute , "GET xxxxxxx.xxx c:\WINDOWS\Temp\xxxxx.xxx"
Do While Inet1.StillExecuting
DoEvents
Loop
Update.Label1.Caption = "Zatvor program xxxxxxxxxxxx a pokracuj v instalacii!"
Shell "c:\WINDOWS\Temp\xxxxxxxx.xxx"
End Sub