By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,365 Members | 3,095 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,365 IT Pros & Developers. It's quick & easy.

Returning exit codes from windows forms application

P: n/a
What is the best way to return an exit code from a VB.NET windows forms app?

My Forms application is dual purpose. It is an interactive windows app. It
is also automated and run via a script and it needs to return an exit code
to that script.

I've tried a few ways to return an exit code.

1. As a forms app with Entry point being Form1, I've tried
Application.Exit(999). It does not return the exit code.

2. As a forms app with
Shared Sub Main() As Integer
Application.Run(New Form1)
Return 999
End Sub

This does not return the exit code.

3. I changed the app type to console and shared sub main() as integer.
This returns an exit code. However, when run interactively, there's always
a console window running at the same time as the form, which is annoying.
In C# a windows forms app actually returns an exit code.
[STAThread]
static void Main()
{
Application.Run(new Login());
return 999;
}
How can I make a VB.NET windows form app that returns an exit code?
Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Minor correction to the post in #2

Shared Function Main() As Integer
Application.Run(New Form1)
Return 999
End Sub

Nov 21 '05 #2

P: n/a
Minor correction to the post in #2

Shared Function Main() As Integer
Application.Run(New Form1)
Return 999
End Sub

Nov 21 '05 #3

P: n/a
"Zeno Lee" <ze******@hotmail.com> schrieb:
is also automated and run via a script and it needs to return an exit code
to that script.

I've tried a few ways to return an exit code.

1. As a forms app with Entry point being Form1, I've tried
Application.Exit(999). It does not return the exit code.

2. As a forms app with
Shared Sub Main() As Integer
Application.Run(New Form1)
Return 999
End Sub

This does not return the exit code.


Did you check the exit code in a batch file, or by starting the process
using 'Process.Start' and examining the 'Process' object's 'ExitCode'?

\\\
Imports System.Diagnostics
..
..
..
Dim p As Process = Process.Start("C:\Test.exe")
p.WaitForExit()
MsgBox(CStr(p.ExitCode))
p.Dispose()
///

The exit code shown in the IDE's output window is wrong!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4

P: n/a
"Zeno Lee" <ze******@hotmail.com> schrieb:
is also automated and run via a script and it needs to return an exit code
to that script.

I've tried a few ways to return an exit code.

1. As a forms app with Entry point being Form1, I've tried
Application.Exit(999). It does not return the exit code.

2. As a forms app with
Shared Sub Main() As Integer
Application.Run(New Form1)
Return 999
End Sub

This does not return the exit code.


Did you check the exit code in a batch file, or by starting the process
using 'Process.Start' and examining the 'Process' object's 'ExitCode'?

\\\
Imports System.Diagnostics
..
..
..
Dim p As Process = Process.Start("C:\Test.exe")
p.WaitForExit()
MsgBox(CStr(p.ExitCode))
p.Dispose()
///

The exit code shown in the IDE's output window is wrong!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

P: n/a
I am checking the %errorlevel% variable from the console. As far as I know,
that is accurate.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eX**************@TK2MSFTNGP14.phx.gbl...
"Zeno Lee" <ze******@hotmail.com> schrieb:
is also automated and run via a script and it needs to return an exit
code to that script.

I've tried a few ways to return an exit code.

1. As a forms app with Entry point being Form1, I've tried
Application.Exit(999). It does not return the exit code.

2. As a forms app with
Shared Sub Main() As Integer
Application.Run(New Form1)
Return 999
End Sub

This does not return the exit code.


Did you check the exit code in a batch file, or by starting the process
using 'Process.Start' and examining the 'Process' object's 'ExitCode'?

\\\
Imports System.Diagnostics
.
.
.
Dim p As Process = Process.Start("C:\Test.exe")
p.WaitForExit()
MsgBox(CStr(p.ExitCode))
p.Dispose()
///

The exit code shown in the IDE's output window is wrong!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6

P: n/a
I am checking the %errorlevel% variable from the console. As far as I know,
that is accurate.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eX**************@TK2MSFTNGP14.phx.gbl...
"Zeno Lee" <ze******@hotmail.com> schrieb:
is also automated and run via a script and it needs to return an exit
code to that script.

I've tried a few ways to return an exit code.

1. As a forms app with Entry point being Form1, I've tried
Application.Exit(999). It does not return the exit code.

2. As a forms app with
Shared Sub Main() As Integer
Application.Run(New Form1)
Return 999
End Sub

This does not return the exit code.


Did you check the exit code in a batch file, or by starting the process
using 'Process.Start' and examining the 'Process' object's 'ExitCode'?

\\\
Imports System.Diagnostics
.
.
.
Dim p As Process = Process.Start("C:\Test.exe")
p.WaitForExit()
MsgBox(CStr(p.ExitCode))
p.Dispose()
///

The exit code shown in the IDE's output window is wrong!

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7

P: n/a
"Zeno Lee" <ze******@hotmail.com> schrieb:
I am checking the %errorlevel% variable from the console. As far as I
know, that is accurate.


Can you post the (batch?) code you use to check it?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8

P: n/a
"Zeno Lee" <ze******@hotmail.com> schrieb:
I am checking the %errorlevel% variable from the console. As far as I
know, that is accurate.


Can you post the (batch?) code you use to check it?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.