.net 程序在線升級

http://www.cnblogs.com/KnightsWarrior/archive/2010/10/20/1856255.html
http://www.cnblogs.com/stoneniqiu/p/3806558.html
配置IIS http://www.sufeinet.com/thread-291-1-1.html
Apache 用戶名和密碼驗證
http://blog.csdn.net/liushu_it/article/details/18735449
借鑑了聖殿騎士寫的dll,更改了下載後刪除old文件

  1. 在引用中添加AutoUpdater.dll,代碼中添加
Imports KnightsWarriorAutoupdater        '實現自動更新的dll
  1. 服務器端配置文件 AutoupdateService.xml
    下面的代碼示例會把文件夾tt以及裏面的1.txt文件一起拷貝到客戶端中,size爲文件大小,並非佔用空間,必須寫對
<?xml version="1.0" encoding="utf-8"?>
<updateFiles>
    <file  path="1.txt"  url="http://10.*.*.*:8011/SerialWrite/tt/1.txt"  lastver="3.2.1.2" size="8" needRestart="True"  />
</updateFiles>
  1. 客戶端配置文件 AutoUpdater.config
<?xml version="1.0" encoding="utf-8"?>
<Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Enabled>true</Enabled>
  <ServerUrl>http://10.*.*.*:8011/SerialWrite/AutoupdateService.xml</ServerUrl>
  <UpdateFileList>
    <LocalFile path="1.txt" lastver="3.2.1.2" size="8" />
  </UpdateFileList>
</Config>
  1. 更新的代碼
'*********************
'自動更新程序
'*********************
Dim bHasError As Boolean = False
Dim autoUpdater As IAutoUpdater = New AutoUpdater()
Try
    autoUpdater.Update()
Catch ex As WebException
    MessageBox.Show("連接自動升級服務器出錯,請檢查網絡連接或聯繫軟件提供者。(Connect remote update server fail.)", "更新程序(UPDATE SOFTWRAE)", MessageBoxButtons.OK, MessageBoxIcon.Error)
    bHasError = True
Catch ex As XmlException
    MessageBox.Show("服務器上的升級文件(AutoupdateService.xml)出錯。(Download the upgrade file error.)", "更新程序(UPDATE SOFTWRAE)", MessageBoxButtons.OK, MessageBoxIcon.Error)
    bHasError = True
Catch ex As Exception
    MessageBox.Show("更新程序出錯。(An error occurred during the upgrade process.)", "更新程序(UPDATE SOFTWRAE)", MessageBoxButtons.OK, MessageBoxIcon.Error)
    bHasError = True
Finally
    If bHasError = True Then
        Try
            autoUpdater.RollBack()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End If
End Try
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章