2014-05-14 50 views
0

我們有一個ClickOnce WPF應用程序。它會在啓動之前檢查是否存在另一個更新版本,但當然如果用戶跳過它,它們不會再被詢問 - 所以我們在應用程序上有一個按鈕來檢查更新。如果存在,它將安裝它,關閉應用程序並重新打開它。問題是,當它重新打開它不再網絡部署!下面是使用的代碼WPF關閉並重啓不再網絡部署

Private Sub Updates_CheckForUpdates(sender As Object, e As RoutedEventArgs) 
    Try 
     Dim vInfo As System.Deployment.Application.UpdateCheckInfo = Nothing 
     If System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed = True Then 
      Dim AD As System.Deployment.Application.ApplicationDeployment = System.Deployment.Application.ApplicationDeployment.CurrentDeployment 
      vInfo = AD.CheckForDetailedUpdate 
      If vInfo.UpdateAvailable = True Then 
       Dim vOutput As String = "There is a new update available for HOA Manager!" & Environment.NewLine 
       vOutput += "Install the update?" 
       Dim vBox As New AppBoxConfirmation(vOutput) 
       If vBox.Show = CommonDialog.CustomDialogResults.Yes Then 
        AD.Update() 
        AppBoxSuccess("HOA Manager was successfully updated, and will now restart!") 
        System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location) 
        'System.Diagnostics.Process.Start(Application.ResourceAssembly.Location) 
        Application.Current.Shutdown() 
       End If 

      Else 
       'HOA Manager is up to date 
       AppBoxSuccess("HOA Manager is up to date!") 
      End If 
     Else 
      AppBoxValidation("The application is not network deployed!") 
      System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location) 
      'System.Diagnostics.Process.Start(Application.ResourceAssembly.Location) 
      Application.Current.Shutdown() 
     End If 
    Catch ex As Exception 
     EmailError(ex) 
    End Try 
End Sub 

下面的代碼檢查上的應用程序顯示的版本號 - 因爲「調試」顯示,我們知道,這不是網絡部署

Public Function ReturnCurrentVersion() As String 
    Dim vBuild As String = "Debug" 
    If System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed Then 
     Dim vVersion As Version = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion 
     Dim vAssembly As Assembly = Assembly.GetExecutingAssembly() 
     Dim vAssemblyName As AssemblyName = vAssembly.GetName() 
     vBuild = vVersion.ToString 
    End If 
    Return vBuild 
End Function 

有什麼建議?

感謝

回答

0

不會知道肯定,直到這後兩個更新在野外被淘汰,但是這可能是答案...

Dim EntryPoint As String = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.UpdatedApplicationFullName 
        System.Diagnostics.Process.Start(EntryPoint) 
+0

嘗試過了,這個工作:-) – gchq