vb.netbatch-fileconsole-applicationclickoncemage

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


I have created a console app that creates a batch file in code, that will automatically update and re-sign my app manifest file using mage.exe when a new version gets published.

This batch file then gets executed by the same console app after it has created it.

I want to know if there is a way to determine if the mage.exe batch file failed in updating or signing the manifest?

Any help or ideas will be appreciated.

UPDATE

As per TnTinMn's comment, I forced the batch to fail on updating the manifest. This returned a exit code of 1. How is it then possible for me to extract that exit code to do my error handling? Im doing the following:

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.

While debugging and looking at the sval object's properties, the exit code is set to 1 but i can't seem to extract it from there.


Solution

  • There are two ways (that I know of) that you can wait for the process to exit before retrieving the Process.ExitCode.

    The first as is a blocking call: Process.WaitForExit

    and the second is to use the Exit event.

    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