2015-04-23 68 views
0

在極少數情況下,我的程序在完成安裝更新後崩潰。它只是給了我一個:「ProgramName已停止響應」錯誤並崩潰。我知道它必須是我的Windows更新安裝的安裝方法中的某個地方,但我無法弄清楚什麼或錯誤在哪裏。fVB.NET完成安裝更新後,Windows Update崩潰

也許有人對WUAPI.dll有一點了解可以幫助我嗎?

該程序是從一個USB棒上運行的,我偶然可以通過將程序移動到桌面上並從那裏運行來「解決」問題,但我想避免讓要做到這一點。而且AFAIK,我的代碼中沒有一個實際訪問usb棒,或者需要在更新安裝過程中訪問usb棒上的程序。當然,我可能只是失去了一些東西非常基本的..

#Region "Installation method" 
    Public Sub iInstallation() 

     Progression = "UpdateInstall" 
     iUpdateInstaller = TryCast(UpdateSession.CreateUpdateInstaller(), IUpdateInstaller) 
     iUpdateInstaller.Updates = NewUpdatesCollection 

     iInstallationJob = iUpdateInstaller.BeginInstall(New iUpdateInstaller_onProgressChanged(Me), New iUpdateInstaller_onCompleted(Me), New iUpdateInstaller_state(Me)) 
    End Sub 
    Public Sub iInstallationComplete() 
     Try 
      Progression = "InstallComplete" 
      iDownloadJob.CleanUp() 
      iInstallationResult = iUpdateInstaller.EndInstall(iInstallationJob) 
      InvokeUIChangeText = "Installation Complete..." 
      InvokeUIChange() 

      If iInstallationResult.ResultCode = OperationResultCode.orcSucceeded Or iInstallationResult.ResultCode = OperationResultCode.orcSucceededWithErrors Then 

        message = "Installation done. " & iInstallationJob.Updates.Count & " Updates installed" 
        caption = "Installation Successfull" 
        buttons = MessageBoxButtons.OK 
        ikon = MessageBoxIcon.Information 
        MessageBox.Show(message, caption, buttons, ikon) 
        Me.Close() 


      Else 

       message = "One or more installations failed to install." 
       caption = "Installation failure" 
       buttons = MessageBoxButtons.OK 
       ikon = MessageBoxIcon.[Error] 
       MessageBox.Show(message, caption, buttons, ikon) 
       Me.Close() 


      End If 
     Catch err As Exception 
      MsgBox(err.Message) 
     End Try 
    End Sub 
    Public Class iUpdateInstaller_onProgressChanged 
     Implements IInstallationProgressChangedCallback 
     Private form1 As WUAPIProgress 

     Public Sub New(mainForm As WUAPIProgress) 
      Me.form1 = mainForm 
     End Sub 

     Public Sub Invoke(installationJob As IInstallationJob, e As IInstallationProgressChangedCallbackArgs) Implements IInstallationProgressChangedCallback.Invoke 
      Dim x As Integer = e.Progress.CurrentUpdatePercentComplete 
      form1.Invoke(Sub() 

          form1.Action.Text = "Installere opdatering " & e.Progress.CurrentUpdateIndex + 1 & "/" & installationJob.Updates.Count & " " & installationJob.Updates.Item(e.Progress.CurrentUpdateIndex + 1).Title 
          form1.ProgressBar1.Value = x 
          form1.Refresh() 

         End Sub) 
     End Sub 
    End Class 
    Public Class iUpdateInstaller_onCompleted 
     Implements IInstallationCompletedCallback 

     Private form1 As WUAPIProgress 

     Public Sub New(mainForm As WUAPIProgress) 
      Me.form1 = mainForm 
     End Sub 

     Public Sub Invoke(installationJob As WUApiLib.IInstallationJob, callbackArgs As IInstallationCompletedCallbackArgs) Implements IInstallationCompletedCallback.Invoke 
      form1.iInstallationComplete() 
     End Sub 
    End Class 

    Public Class iUpdateInstaller_state 
     Private form1 As WUAPIProgress 

     Public Sub New(mainForm As WUAPIProgress) 
      Me.form1 = mainForm 
      msgbox("Starting installation") 
     End Sub 
    End Class 
#End Region 

也可能是值得注意的關閉事件

Private Sub WUAPIProgress_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing 
    Try 


     Dim AutoUpdate = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\", True) 
     AutoUpdate.SetValue("AUOptions", 4) 
     If Progression = "UpdateSearch" Or Progression = "SearchComplete" Then 


      iSearchJob.RequestAbort() 


     ElseIf Progression = "UpdateDownload" Or Progression = "UpdateComplete" Then 
      iDownloadJob.RequestAbort() 



     ElseIf Progression = "UpdateInstall" Or Progression = "InstallComplete" Then 


      iInstallationJob.RequestAbort() 

     End If 



    Catch err As Exception 
     MsgBox(err.Message) 
    End Try 
End Sub 

,並形成閉合和形式時,我有以下:

Private Sub WUAPIProgress_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed 
    Me.Dispose() 
End Sub 

以爲我有一些錯誤輸出,不幸的是沒有。這與其他事情有關。

編輯:

代碼追趕全球:

Namespace My 

' The following events are available for MyApplication: 
' 
' Startup: Raised when the application starts, before the startup form is created. 
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally. 
' UnhandledException: Raised if the application encounters an unhandled exception. 
' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected. 
Partial Friend Class MyApplication 

    Private Delegate Sub SafeApplicationThreadException(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs) 

    Private Sub ShowDebugOutput(ByVal ex As Exception) 

     Dim frmD As New frmDebug() 
     frmD.rtfError.AppendText(ex.ToString()) 
     frmD.ShowDialog() 

     Environment.Exit(0) 

    End Sub 

    Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup 


     AddHandler System.Windows.Forms.Application.ThreadException, AddressOf app_ThreadException 


     AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf AppDomain_UnhandledException 
    End Sub 

    Private Sub app_ThreadException(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs) 


     If MainForm.InvokeRequired Then 

      MainForm.Invoke(New SafeApplicationThreadException(AddressOf app_ThreadException), New Object() {sender, e}) 
     Else 
      ShowDebugOutput(e.Exception) 
     End If 

    End Sub 

    Private Sub AppDomain_UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs) 

     ShowDebugOutput(DirectCast(e.ExceptionObject, Exception)) 

    End Sub 

    Private Sub MyApplication_UnhandledException(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException 

     ShowDebugOutput(e.Exception) 

    End Sub 

End Class 


End Namespace 

編輯:

我已經查明瞭可能是主要問題。

該程序是從USB棒上運行的,如果該USB棒在程序完成之前被移除,無論出於何種原因,該程序都會嘗試到達該應用程序從(usb棒)開始的地方以及它然後失敗,並崩潰。

所以看來我將不得不讓程序複製自己,然後從計算機上的位置運行。 然而奇怪的是,它並不總是一個問題。但在運行Windows 8.1的虛擬機上,我幾乎每一次都會觀察它。

我想我會玩它多一點,因爲我更喜歡能夠刪除USB程序啓動後運行的USB棒。難題我爲什麼必須訪問.exe才能能完成嗎?

+1

「它崩潰」不是一個合適的問題描述。您*必須*爲AppDomain.CurrentDomain.UnhandledException事件編寫事件處理程序,以便未處理的異常變爲可診斷狀態。發佈異常消息和堆棧跟蹤,您現在必須在此獲得幫助。 –

+0

好的..謝謝。我會研究這:)這也會抓住「程序已停止響應,必須關閉」 - 對話框?或者,該對話框是線程外發生異常的直接結果,這意味着您不會得到通常的「未處理的異常」對話框? – Gematria

+0

是的,您在顯示或記錄異常之後在您的事件處理程序中調用Environment.Exit(),以便不顯示此WER對話框。 –

回答

0

不應該有任何問題使其成爲全球,只要使用此代碼:

Public Shared Sub Main(args As String()) 
    AppDomain.CurrentDomain.UnhandledException += New UnhandledExceptionEventHandler(AddressOf ApplicationUnhandledException) 
End Sub 

Private Sub ApplicationUnhandledException(sender As Object, e As UnhandledExceptionEventArgs) 
     'Write all the information to help diagnose the problem 
End Sub 

然後提供漢斯& /或我與信息。

+0

它在最初的問題。這就是我可以從中得到的輸出。我在applicationevents.vb中捕獲的代碼也是在最初的問題中。 – Gematria