检查 Mage.exe 批量清单更新是否成功 - ClickOnce

Check if Mage.exe batch manifest update was successful or not - ClickOnce

我创建了一个控制台应用程序,它在代码中创建一个批处理文件,当新版本发布时,它将使用 mage.exe 自动更新和重新签署我的应用程序清单文件。

这个批处理文件在创建后由同一个控制台应用程序执行。

我想知道是否有办法确定 mage.exe 批处理文件是否更新或签署清单失败?

任何帮助或想法将不胜感激。

更新

根据 TnTinMn 的评论,我强制批处理在更新清单时失败。这返回了退出代码 1。那么我如何提取该退出代码来进行错误处理呢?我正在执行以下操作:

Dim procInfo As New ProcessStartInfo()
procInfo.UseShellExecute = True
procInfo.FileName = (sDriveLetter & ":\updatemanifest.bat")
procInfo.WorkingDirectory = ""
procInfo.Verb = "runas"
procInfo.WindowStyle = ProcessWindowStyle.Hidden
Dim sval As Object = Process.Start(procInfo) 'I tested the object to see if there is indeed a value that i can use.

在调试和查看 sval 对象的属性时,退出代码设置为 1,但我似乎无法从那里提取它。

有两种方法(据我所知)可以在检索 Process.ExitCode 之前等待进程退出。

第一个 as 是阻塞调用:Process.WaitForExit

第二个是使用Exit事件。

Private Sub RunProcess()
    Dim psi As New ProcessStartInfo()
    psi.UseShellExecute = True
    psi.WindowStyle = ProcessWindowStyle.Hidden
    psi.FileName = "cmd.exe"
    psi.Arguments = "/c Exit 100"


    Dim proc As Process = Process.Start(psi)
    proc.EnableRaisingEvents = True
    AddHandler proc.Exited, AddressOf ProcessExited
End Sub

Private Sub ProcessExited(sender As Object, e As EventArgs)
    Dim proc As Process = DirectCast(sender, Process)
    proc.Refresh()
    Dim code As Int32 = proc.ExitCode
    Me.BeginInvoke(Sub() MessageBox.Show(String.Format("Process has exited with code: {0}", code)), Nothing)
    proc.Dispose()
End Sub