我创建了一个控制台应用程序,可以在代码中创建一个批处理文件,当新版本发布时,它将使用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,但我似乎无法从那里提取它。
答案 0 :(得分:0)
在检索Process.ExitCode之前,有两种方法(我知道)可以等待进程退出。
第一个是阻止通话: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