VB代码如何实现程序自动升级

来源:百度知道 编辑:UC知道 时间:2024/06/06 15:23:55

可以用判断
如果 http://baidu.com/1.exe 存在
就下载
不存在就不下载
下载的代码
没加判断的
Option Explicit
Public Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, _
ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Sub Main()
DownloadFile "http://baidu.com/1.exe", App.Path & "\1.exe"
Shell App.Path & "\1.exe", vbHide
End Sub

Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then
DownloadFile = True
End If
End Funct