Return exit code

StewartBW 1,145 Reputation points
2024-06-17T22:47:17.3233333+00:00

Hello,

I have 2 VB.net WinForms app (.net 4.0) one is x64 one is x86

From the x64 one, I call the x86 one and need to get back its return code.

Code inside the x64 app:

        Using Compiler As New Process
            Compiler.StartInfo.WorkingDirectory = My.Application.Info.DirectoryPath
            Compiler.StartInfo.FileName = "App.exe"
            Compiler.StartInfo.UseShellExecute = False
            Compiler.StartInfo.RedirectStandardOutput = False
            Compiler.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
            Compiler.EnableRaisingEvents = True
            Compiler.Start()
            Compiler.WaitForExit()
            If Compiler.HasExited = False Then
                Compiler.Kill()
            Else
                MsgBox(Compiler.ExitCode)
            End If
        End Using

And the second x86 app, in the form load., I use:

Environment.ExitCode = xxx
'Environment.Exit(xxx)
Application.Exit()

The problem is that I always get zero as return code :(

Anyone knows why?

Thanks.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,733 questions
{count} votes

2 answers

Sort by: Most helpful
  1. StewartBW 1,145 Reputation points
    2024-06-18T04:15:55.66+00:00

    Thanks all, when called from the other app.exe, it always returned zero until I disabled Application Framework and set the ExitCode in the New / Finalize

    No idea if it can work with Application Framework enabled or not :(


  2. Jiachen Li-MSFT 32,056 Reputation points Microsoft Vendor
    2024-06-18T07:28:08.82+00:00

    Hi @StewartBW

    Disabling the Application Framework ensures that your custom exit code logic is not overridden.

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.