如何设置非控制台应用程序的退出代码? [英] How to set exit code of non-console app?

查看:118
本文介绍了如何设置非控制台应用程序的退出代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C#编写的Windows应用程序,我想在它运行时返回一个非零的

退出代码。问题是,作为一个Windows应用程序,

似乎没有办法控制它。

Main函数返回的值对应用程序返回的值没有影响。

Windows应用程序立即退出,其窗口仍然打开。是

有一种方法可以更改Windows应用程序退出的值。基本上

我希望它返回1而不是0.我需要这样做,因为

应用程序是由另一个检查退出的应用程序启动的

代码和这个特定的应用程序期望它启动的程序返回一个非零的退出代码。

解决方案

< blockquote>尝试设置Environment.ExitCode


谢谢,

Michael C.,MCDBA


" Peter Steele" ; < PS ***** @ z-force.com>在留言中写道

新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...

我有一个用C#编写的Windows应用程序,我想在它运行时返回
非零退出代码。问题是,作为一个Windows应用程序,
似乎没有办法控制它。
Main函数返回的值对应用程序返回的值没有影响。
Windows应用程序立即退出,其窗口仍然打开。
有没有办法更改Windows应用程序退出的值。
基本上我希望它返回1而不是0.我需要这样做,因为
应用程序是由另一个检查退出代码的应用程序启动的,这个特定的应用程序需要该程序它会启动
来返回一个非零退出代码。



我已经找到了这个,但它没有''似乎有任何影响。我在Main中添加了




Environment.ExitCode = 1;


但应用程序仍然退出我试过把它放在

应用程序的主要构造函数中,这仍然没有任何影响。如果我编译

应用程序作为控制台应用程序,这可以工作,但不是作为Windows

应用程序。


所以我在哪里应该设置这个ExitCode属性吗?


" Michael C" < MI ****** @ nospam.org>在消息中写道

news:da ********************** @ news4.srv.hcvlny.cv。 net ...

尝试设置Environment.ExitCode

谢谢,
Michael C.,MCDBA

Peter Steele < PS ***** @ z-force.com>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...

我写了一个Windows应用程序在C#中,我希望在运行时返回


非零

退出代码。问题是,作为一个Windows应用程序,
似乎没有办法控制它。
Main函数返回的值对应用程序返回的值没有影响。
Windows应用程序立即退出,其窗口仍然打开。


有一种方法可以更改Windows应用程序退出的值。


基本上

我希望它返回1而不是0.我需要这样做,因为
应用程序是由另一个检查退出代码的应用程序启动的,这个特定的应用程序希望它启动的程序


返回一个非零退出代码。




尝试将该行放在表单的.Closing事件中。


谢谢,

Michael C.,MCDBA


" Peter Steele" < PS ***** @ z-force.com>在消息中写道

新闻:大江*************** @ TK2MSFTNGP11.phx.gbl ...

我会已经发现了这个,但似乎没有任何效果。我在Main中添加了




环境.ExitCode = 1;

但应用程序仍然以0退出。我尝试将它放入
应用程序的主要构造函数,这仍然没有任何影响。如果我将应用程序编译为控制台应用程序,这可以工作,但不能作为Windows
应用程序。

那么我应该在哪里设置这个ExitCode属性?

Michael C < MI ****** @ nospam.org>在消息中写道
新闻:da ********************** @ news4.srv.hcvlny.cv。 net ...

尝试设置Environment.ExitCode

谢谢,
Michael C.,MCDBA

Peter Steele < PS ***** @ z-force.com>在消息中写道
新闻:%2 **************** @ TK2MSFTNGP09.phx.gbl ...

我写了一个Windows应用程序在C#中,我希望在运行时返回


非零

退出代码。问题是,作为一个Windows应用程序,
似乎没有办法控制它。主函数
返回的值对应用程序返回的值没有影响。
Windows应用程序立即退出,其窗口仍然是
打开。

< blockquote class =post_quotes>

有一种方法可以更改Windows应用程序退出的值。


基本上

我想要它返回1而不是0.我需要这样做,因为
应用程序是由另一个检查


退出代码的应用程序启动的,而这个特定的应用程序需要它的程序



启动

返回非零退出代码。





I have a Windows application written in C# that I want to return a non-zero
exit code when it it run. The problem is that as a Windows application,
there doesn''t seem to be a way to control this. The value returned by the
Main function has no impact on the value returned by the application.
Windows applications exit immediately, leaving their windows still open. Is
there a way to change the value a Windows application exits with. Basically
I want it to return 1 instead of 0. I need to do this because the
application is launched by another application that checked for the exit
code and this particular application expects that the program it launches to
return a non-zero exit code.

解决方案

Try setting Environment.ExitCode

Thanks,
Michael C., MCDBA

"Peter Steele" <ps*****@z-force.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

I have a Windows application written in C# that I want to return a non-zero exit code when it it run. The problem is that as a Windows application,
there doesn''t seem to be a way to control this. The value returned by the
Main function has no impact on the value returned by the application.
Windows applications exit immediately, leaving their windows still open. Is there a way to change the value a Windows application exits with. Basically I want it to return 1 instead of 0. I need to do this because the
application is launched by another application that checked for the exit
code and this particular application expects that the program it launches to return a non-zero exit code.



I''d already found this but it doesn''t seem to have any effect. I added the
line

Environment.ExitCode = 1;

in Main but the application still exited with 0. I tried putting it in the
app''s main constructor and this still didn''t have any effect. If I compile
the app as a console application this works but not as a Windows
application.

So where am I supposed to set this ExitCode property?

"Michael C" <mi******@nospam.org> wrote in message
news:da**********************@news4.srv.hcvlny.cv. net...

Try setting Environment.ExitCode

Thanks,
Michael C., MCDBA

"Peter Steele" <ps*****@z-force.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

I have a Windows application written in C# that I want to return a


non-zero

exit code when it it run. The problem is that as a Windows application,
there doesn''t seem to be a way to control this. The value returned by the
Main function has no impact on the value returned by the application.
Windows applications exit immediately, leaving their windows still open.


Is

there a way to change the value a Windows application exits with.


Basically

I want it to return 1 instead of 0. I need to do this because the
application is launched by another application that checked for the exit
code and this particular application expects that the program it launches


to

return a non-zero exit code.




Try putting that line in the .Closing event of your form.

Thanks,
Michael C., MCDBA

"Peter Steele" <ps*****@z-force.com> wrote in message
news:Oe***************@TK2MSFTNGP11.phx.gbl...

I''d already found this but it doesn''t seem to have any effect. I added the
line

Environment.ExitCode = 1;

in Main but the application still exited with 0. I tried putting it in the app''s main constructor and this still didn''t have any effect. If I compile
the app as a console application this works but not as a Windows
application.

So where am I supposed to set this ExitCode property?

"Michael C" <mi******@nospam.org> wrote in message
news:da**********************@news4.srv.hcvlny.cv. net...

Try setting Environment.ExitCode

Thanks,
Michael C., MCDBA

"Peter Steele" <ps*****@z-force.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

I have a Windows application written in C# that I want to return a


non-zero

exit code when it it run. The problem is that as a Windows application,
there doesn''t seem to be a way to control this. The value returned by the Main function has no impact on the value returned by the application.
Windows applications exit immediately, leaving their windows still open.

Is

there a way to change the value a Windows application exits with.


Basically

I want it to return 1 instead of 0. I need to do this because the
application is launched by another application that checked for the

exit code and this particular application expects that the program it


launches to

return a non-zero exit code.





这篇关于如何设置非控制台应用程序的退出代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆