#眉標=Visual Studio 2005 (2) #副標=VS 2005新功能 #大標=ClickOnce - 簡化軟體的部署程序 #作者=文/沈炳宏 ============程式============== 程式1 Imports System.Deployment.Application Imports System.ComponentModel Imports System.Windows.Forms … Private Sub InstallUpdateSyncWithInfo() Dim info As UpdateCheckInfo = Nothing If (ApplicationDeployment.IsNetworkDeployed) Then Dim AD As ApplicationDeployment = ApplicationDeployment.CurrentDeployment Try info = AD.CheckForDetailedUpdate() Catch dde As DeploymentDownloadException MessageBox.Show("目前無法下載新版程式. " + ControlChars.Lf + ControlChars.Lf + "請檢查網路狀態, 錯誤訊息: " + dde.Message) Return Catch ioe As InvalidOperationException MessageBox.Show("無法更新應用程式, 錯誤訊息: " + ioe.Message) Return End Try If (info.UpdateAvailable) Then Dim doUpdate As Boolean = True If (Not info.IsUpdateRequired) Then Dim dr As DialogResult = MessageBox.Show( "有一個更新程式. 是否要現在更新?", "有更新程式", MessageBoxButtons.OKCancel) If (Not System.Windows.Forms.DialogResult.OK = dr) Then doUpdate = False End If End If If (doUpdate) Then Try AD.Update() MessageBox.Show("應用程式已經更新, 現在要重新啟動") Application.Restart() Catch dde As DeploymentDownloadException MessageBox.Show("無法安裝更新程式. " + ControlChars.Lf + ControlChars.Lf + "請檢查網路狀態或稍後再試.") Return End Try End If End If End If End Sub ============程式=============