此主题相关图片如下:4.png

此主题相关图片如下:5.png

设置完之后,就可以编译可执行文件了。我起的名字为update.exe
第二步:代码设置部分。
项目事件中:
BeforeOpenProject
Dim ver As String = ApplicationPath & "文件名.exe"
'首先检测本地是否存在update.dat,如果不存在.则提示错误.
Dim update As String = ApplicationPath & "update.dat"
'升级记录版本号文件。
Dim txt As String = ApplicationPath & "tmp.txt"
'解压缓存文件。
Dim autoupdate As String = ApplicationPath & "autoupdate.bat"
'升级批处理文件。
Dim updatexe As String = ApplicationPath & "update.exe"
'自解压升级包
Dim vl As String
Dim tx As String = "http://域名/update.txt"
'服务器上版本标志。
Dim upexe As String = "http://域名/update.exe"
'服务器上升级包
Dim myFileVersionInfo As System.Diagnostics.FileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(ver)
If FileSys.FileExists(update) Then
'如果存在,则检测文件版本是否和文件版本一致.先对update文件进行解密.
DecryptFile(update,txt,"加密字符串")
vl = FileSys.ReadAllText(txt)
Dim val() As String = vl.Split(Chr(13) & Chr(10))
If myFileVersionInfo.FileVersion() <> val(0).Remove(0,4) Then
'比对版本号是否一致,如果不一致.那么再自动升级文件是否存在
MessageBox.Show(myFileVersionInfo.FileVersion() & val(0).Remove(0,4))
If FileSys.FileExists(updatexe) Then
MessageBox.Show("检测到升级文件,系统将进行升级.")
Dim proc As new Process
proc.file = autoupdate
proc.Start()
'系统进程关闭.进行升级.
Else
MessageBox.Show("系统需要升级,将进行升级请不要中断.")
Network.DownloadFile(upexe, ApplicationPath & "update.exe" ,"" ,"" ,True, 100000, True)
If FileSys.FileExists(updatexe) Then
MessageBox.Show("检测到升级文件,系统将进行升级.")
Dim proc As new Process
proc.file = autoupdate
proc.Start()
End If
End If
Else
'如果版本号一致,那么比对服务器上文件信息.
If Network.Ping(sheet1(3,1).Value,1000) = False Then '如果无法接通
MessageBox.Show("升级服务器出现故障,请联系尚起网络科技客服QQ:2608704980")
Else
'如果能接通,那么读取服务器升级文件.
' Dim sup As String =
Network.DownloadFile(tx, ApplicationPath & "update.txt" ,"" ,"" ,True, 100000, True)
If FileSys.FileExists(ApplicationPath & "update.txt") Then
vl = FileSys.ReadAllText(ApplicationPath & "update.txt")
Dim val1() As String = vl.Split(Chr(13) & Chr(10))
If myFileVersionInfo.FileVersion() <> val1(0).Remove(0,4) Then
MessageBox.Show("检测到新的版本,版本号:" & val1(0).Remove(0,4) & "系统将自动进行下载,请不要中断下载!")
Network.DownloadFile(upexe, ApplicationPath & "update.exe" ,"" ,"" ,True, 100000, True)
If FileSys.FileExists(updatexe) And FileSys.FileExists(autoupdate) Then
MessageBox.Show("检测到升级文件,系统将进行升级.")
Dim proc As new Process
proc.file = autoupdate
proc.Start()
'系统进程关闭.进行升级.
Else
MessageBox.Show("系统升级文件丢失,请重新安装本系统.")
End If
Else
MessageBox.Show("本版本是最新版本,不需要升级!")
End If
FileSys.DeleteFile(ApplicationPath & "update.txt")
End If
End If
End If
Else
MessageBox.Show("升级文件丢失,请重新安装本系统.")
End If