急!急!求VB.NET2003,C/S程序自动升级源代码,要能使用!!!!
如题!!如能使用可再送100分!!!!!
只要VB.NET代码!!!!
问题点数:100、回复次数:18Top
1 楼scow(怡红快绿之小橙子|和谐权是第4代人权)回复于 2006-12-12 11:50:37 得分 0
借贵地同问一下, 有个实现自动更新的组件叫什么名字啊(好像是addupdater, 具体忘了,现在查不到)Top
2 楼cansum396(漆黑的夜)回复于 2006-12-12 12:01:01 得分 0
smart clientTop
3 楼51Crack()回复于 2006-12-12 12:15:02 得分 0
http://www.codeproject.com/vb/net/autoupdate.aspTop
4 楼enslaver(菜鸟。。。。)回复于 2006-12-12 13:49:40 得分 0
也可发我邮箱enslaver_m@163.comTop
5 楼yinliaobao(newren)回复于 2006-12-12 13:50:36 得分 0
jf
Top
6 楼zlhxx89()回复于 2006-12-12 14:13:49 得分 0
路过。。顺便说下
如果,LZ的程序能用NET2005自带的ClickOnce发布(这个发布办法,不能改程序安装路径),那么,NET框架里有现成的类可以使用,甚至,只要在发布程序中设置成自动更新,LZ可以不需要一行代码,缺点是:1 :程序启动或者关闭时自动更新,客户端无法进行设置。 2 同样,不能更改程序安装路径 3 似乎,更新的方式,是程序文件完全替换。
我贴下,我程序更新部分的代码,LZ自己组合一下。
Try
If MessageBox.Show("It begin to Update,may have some minutes delay", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Me.Cursor = Cursors.WaitCursor
Me.Refresh()
If My.Application.Deployment.CheckForUpdate = True Then
Dim info As Application.UpdateCheckInfo = My.Application.Deployment.CheckForDetailedUpdate
lblnow.Text = My.Application.Deployment.CurrentVersion.ToString
lblnew.Text = info.AvailableVersion.ToString
lblsize.Text = CInt(info.UpdateSizeBytes / 1024) & "KB"
cmdUpdate.Enabled = True
Else
MessageBox.Show("It is Up-to-date", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information)
lblnow.Text = My.Application.Deployment.CurrentVersion.ToString
lblnew.Text = My.Application.Deployment.CurrentVersion.ToString
lblsize.Text = 0 & "KB"
cmdUpdate.Enabled = False
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
Me.Cursor = Cursors.Default
End Try
Try
MessageBox.Show("It begin to Update,may have some minutes delay", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Cursor = Cursors.WaitCursor
My.Application.Deployment.Update()
If MessageBox.Show("Update Complated. Only Restart Can use New Edition.Do you want to Restart?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
System.Windows.Forms.Application.Restart()
Else
cmdUpdate.Enabled = False
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Me.Cursor = Cursors.Default
End TryTop
7 楼zlhxx89()回复于 2006-12-12 14:17:29 得分 0
注意,上面的代码,只能用于使用CLickOnce发布的程序,且只有真正发布以后,才能进行调试,否则,会报程序不是发布版本的错误。也就是说,这个代码,不能在IDE中调试。Top
8 楼enslaver(菜鸟。。。。)回复于 2006-12-12 21:26:10 得分 0
在CSDN中这类的帖子很多,可就是没个能用的,那个好心人帮帮忙啊Top
9 楼chenjunhui(熊猫哥哥)回复于 2006-12-13 09:19:03 得分 0
顶是硬道理Top
10 楼MSTOP(陈建华)回复于 2006-12-13 10:04:47 得分 0
将你的源程序写到数据库里
文件名,版本.
客户端用XML或INI记录
文件名,版本.
每次启动时没有启动程序,只启动升级程序.检查两值者的版本是否一至,如果不一至,则从数据库中将文件内容取出.覆盖本地文件.然后.启动主程序.
Top
11 楼cupoflife(修必远)回复于 2006-12-13 10:24:00 得分 0
我有一个用VB开发的C/S更新软件,通过它可以方便地进行软件自动更新或应用程序升级,及注册更新后的组件(DLL、OCX文件)。可以设置不同的更新程序路径。
以下是说明:
;' ServerPath= ;要更新文件存放的路径
;' FileN=........ ;要更新的目录、文件名 --> 另存的路径
;' Filen=[End] ;表示结束,必须存在
;' ExecuteProgram=: ;本程序要执行的程序名
;%AppFolder% Your application's main directory, where all of your files and folders
; will be installed.
;%DesktopFolder% The path to the user's Desktop folder. On Windows NT/2000/XP, this is
; the path from the per-user profile.
;%MyDocumentsFolder% The user's personal (My Documents) folder on their system. Usually this
; is something like "C:\Documents and Settings\YourName\My Documents" on
; Windows 2000/XP and "C:\My Documents" on Windows 98/ME.
; Note: Windows 95 did not have the My Documents folder and this variable
; will return "C:" if run on such a system.
;%StartProgramsFolder% The path to the user's Startup folder. On Windows NT/2000/XP, this is
the path from the per-user profile
;%SystemFolder% The path to the user’s Windows System folder (e.g. "C:\Windows\System").
;%TempFolder% The path to the user's Temp folder.
;%WindowsFolder% The path to the user’s Windows folder (e.g. "C:\Windows").
;
[ServerUpdate]
;更新文件的源目录
ServerPath=\\Ntserver\Persetup\
;要更新的文件列表
File1=BY.ocx
;无更新目标目录,则将BY.ocx当前程序执行的目录下(与参数%AppFolder%相同)
1File2=\\Ntserver\Persetup\BY.ocx --> c:\ta.a
;将BY.ocx更新为C:\ta.a文件
1File3=\\Ntserver\Persetup1\BY.ocx --> %MyDocumentsFolder%
;将by.ocx更新到我的文档目录下
1File4=BY.ocx --> %StartProgramsFolder%
;将by.ocx更新到开始菜单目录下
1File5=BY.ocx --> %AppFolder%
;将by.ocx更新到当前程序执行的目录下
1File6=BY.ocx --> %TempFolder%
;将by.ocx更新到临时目录下
1File7=*.* --> %WindowsFolder%
;将\\Ntserver\Persetup\目录下所有文件更新到Windows目录下
;[End]标志是必须的,否则不知道什么时候文件结束
File8=[End]
;要执行的程序文件名
ExecuteProgram=Human.EXETop
12 楼enslaver(菜鸟。。。。)回复于 2006-12-14 16:00:27 得分 0
理论大家都知道,可编码比较麻烦,谁给个,或发我邮箱里面,enslaver_m@163.com
谢谢Top
13 楼scow(怡红快绿之小橙子|和谐权是第4代人权)回复于 2006-12-14 16:55:55 得分 0
楼主把理论总结一下嘛(几种做法,实现的思路等等),方便大家写代码。俺也想听听。Top
14 楼terry1021_82(小狐狸)回复于 2006-12-14 17:36:06 得分 0
aTop
15 楼HAVENT(夜雨流星℡)回复于 2006-12-14 17:49:27 得分 0
主要是思路,就算做好了,部署也不是简单的事情Top
16 楼MSTOP(陈建华)回复于 2006-12-15 13:59:16 得分 0
Dim FileList() As RefFileInfo
Dim M_LngRev As String
Private Sub FrmDownLoad_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Visible = False
Call InitForm()
Me.Close()
End Sub
Public Sub InitForm()
Dim FileDataSet As New DataSet
Dim FileDataRow As DataRow
Dim StrSql As String
Dim IniFile As String
Dim FileID As Integer = 0
Dim LocalDir As String
Dim LocalFileName As String
Dim LocalVer As String
Dim RefFlag As Boolean
Dim SucFlag As Boolean
On Error Resume Next
SucFlag = True
Label2.Text = ""
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
'//这里加入初始化代码
P_ExePath = Application.StartupPath() '//程序所有路径.
If Microsoft.VisualBasic.Right(P_ExePath, 1) <> "\" Then P_ExePath = P_ExePath & "\"
'取客户端设置
P_ServerInfo.LoginServerName = GetSetting("CGRagtrade", "UserLogin", "LoginServerName", "(local)")
P_ServerInfo.LoginUserName = GetSetting("CGRagtrade", "UserLogin", "LoginUserName", "SA")
P_ServerInfo.LoginPassWord = GetSetting("CGRagtrade", "UserLogin", "LoginPassWord", "123")
IniFile = P_ExePath & "Refresh.ini"
P_SqlConn = CreateSqlConn(P_ServerInfo.LoginServerName, _
"MC_CRM_Data", _
P_ServerInfo.LoginUserName, _
P_ServerInfo.LoginPassWord)
If P_SqlConn.State <> 1 Then
Me.Cursor = System.Windows.Forms.Cursors.Default
Dim Frm As New FrmConfigClid
M_LngRev = Frm.LoadForm(Me)
If M_LngRev = 0 Then
Me.Close()
Exit Sub
End If
End If
StrSql = "SELECT FileName,Dir,VER,IsReg FROM DN_Refresh"
FileDataSet = GetSqlDataSet(P_SqlConn, StrSql)
If FileDataSet.Tables(0).Rows.Count > 0 Then
For Each FileDataRow In FileDataSet.Tables(0).Rows
LocalFileName = "" & FileDataRow("FileName")
If Len(LocalFileName) > 0 Then
LocalVer = GetIniStr("MC_CRM", LocalFileName, IniFile)
If CSng(Val(LocalVer)) < CSng(Val("" & FileDataRow("VER"))) Then '//如果服务器的版本大于当前版要.则记录.
ReDim Preserve FileList(FileID)
FileList(FileID).Name = CStr("" & FileDataRow("FileName"))
FileList(FileID).Dir = CStr("" & FileDataRow("Dir"))
FileList(FileID).Ver = CStr("" & FileDataRow("Ver"))
FileList(FileID).IsReg = CInt(Val("" & FileDataRow("IsReg")))
FileID += 1
End If
End If
Next
'==========================================
If FileID > 0 Then
Me.Show()
PrgNNID.Maximum = FileID
PrgNNID.Value = 0
System.Windows.Forms.Application.DoEvents()
System.Windows.Forms.Application.DoEvents()
For FileID = 0 To UBound(FileList, 1)
PrgNNID.Value = FileID + 1
FileList(FileID).Dir = Replace(FileList(FileID).Dir, "%AppDir%", P_ExePath) '//替换为具体目录名.( %WinDir% 不用替换)
If IO.Directory.Exists(FileList(FileID).Dir) = False Then IO.Directory.CreateDirectory(FileList(FileID).Dir) '//如果目录不存在,则建立.
LocalFileName = FileList(FileID).Dir & "\" & FileList(FileID).Name
LocalFileName = Replace(LocalFileName, "\\", "\")
If IO.Directory.Exists(P_ExePath & "BAK") = False Then IO.Directory.CreateDirectory(P_ExePath & "BAK") '//如果目录不存在,则建立.
System.Windows.Forms.Application.DoEvents()
IO.File.Copy(P_ExePath & FileList(FileID).Name, P_ExePath & "BAK\" & FileList(FileID).Name) '//备份当前文件
Err.Clear()
RefFlag = GetDbBinary(P_SqlConn, "SELECT RefFile FROM DN_Refresh WHERE FileName='" & FileList(FileID).Name & "'", LocalFileName) '//取服务器文件.
System.Windows.Forms.Application.DoEvents()
If CInt(FileList(FileID).IsReg) = 1 Then System.Diagnostics.Process.Start("regsvr32.exe " & Chr(34) & LocalFileName & Chr(34) & " /s")
Label2.Text = FileList(FileID).Name
System.Windows.Forms.Application.DoEvents()
If Err.Number = 0 Then
WriteIniStr("MC_CRM", FileList(FileID).Name, FileList(FileID).Ver, IniFile) '//如果更新成功,则记录
Else
SucFlag = False '//如果错误不为零,标志更新失败.
End If
Err.Clear()
System.Windows.Forms.Application.DoEvents()
Next
End If
End If
Me.Visible = False
If Not SucFlag Then
Me.Cursor = System.Windows.Forms.Cursors.Default
MsgBox("版本更新不成功,请找管理员!", MsgBoxStyle.OkOnly, "版本更新")
Else
System.Diagnostics.Process.Start("CGRagtrade.exe")
Me.Cursor = System.Windows.Forms.Cursors.Default
End If
End SubTop
17 楼enslaver(菜鸟。。。。)回复于 2006-12-17 06:35:32 得分 0
???????????????Top
18 楼bejon(阿牛[如果我懂,必坦诚相告;如果您懂,请不吝赐教。])回复于 2006-12-17 16:41:06 得分 0
晕,很简单的啊,不用几行代码就能写一个更新软件
大概思路:
1.程序起动前使用webclient把放更新信息的网页拉下来,检查一下是否有新版本推出,那网页同时保存了需要更新的程序名字,版本,和需要更新的文件清单,及md5码(用来校验文件下载后是否一至)
2.如果发现需要更新,把当前程序的运行全名及句柄以及需要下载的文件清单(清单有需要的信息)通过命令行传给更新程序,更新程序根据句柄关闭正在运行的更新程序,然后使用webclient下载,下载完了filecopy过去,然后重新启动目标程序。
更新软件我一直是使用自己写的,才24K,哈。Top





