如何使我的应用程序始终运行(启动时启动,如果被杀死或崩溃则重新启动)? [英] How can I make my application run ALL THE TIME (launch at startup, restart if killed or crashed)?

查看:410
本文介绍了如何使我的应用程序始终运行(启动时启动,如果被杀死或崩溃则重新启动)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个Windows应用程序,该应用程序将在启动过程中运行,并且如果稍后终止(例如,由于用户在任务管理器中将其杀死),它将自动重新启动.我在想,也许将其创建为Windows服务会有所帮助.

我知道我可以在注册表中添加一个条目,这样我的应用程序将在启动时自动启动,但是即使从任务管理器中关闭它,我也需要我的应用程序才能继续运行.有什么方法可以检测到这种情况,然后自动将其重新启动吗?

也许我可以创建一个充当看门狗"的Windows服务-定期检查我要保留的进程是否存在,如果未运行,请重新启动它?

I''m trying to create a Windows application that will run during startup and, if terminated later on (say, by a user killing it in the task manager), will restart automatically. I was thinking that perhaps creating it as a Windows service would help.

I know that I can add an entry to registry such that my application will be started automatically at bootup, but I need my application to continue running even if it is closed from task manager. Is there a way to detect this somehow, and then to restart it automatically?

Perhaps I could create a Windows service that would act as a "watchdog" - periodically checking for the existence of the process I wish to preserve, and restarting it if it''s not running?

推荐答案

写道:​​

将应用程序添加到注册表是另一种选择

Adding the app to the registry is another option



你认为这是什么意思 ?您无法将应用添加到注册表中.

您需要运行一个额外的进程,如果进程停止,它将启动您的进程.即使您的应用程序不支持,此过程也将是一项服务.



What do you think this means ? You can''t add an app to the registry.

You need an extra process running, which will start your process if it stops. This process would be a service, even if your app is not.


Mangeshd写道:
Mangeshd wrote:

"i可以将exe条目添加到注册表中...确保我的应用程序将在启动时启动..

但是我需要即使从任务管理器关闭了应用程序,我的应用程序也应该永远运行...我需要检测和处理此问题的方法...以自动重新启动...

如果我启动另一个应用程序来监视我的第一个应用程序,并且两个应用程序都终止了,那么??????????????????

如何启动我的主applcation.exe ???????"

"i can add exe entry to registry...so sure that my application will be start at bootup..

but i need my application should run forever even if application is closed from task manager...i need the way to detect and handle this...to restart it automatically...

if i start another application to monitor my 1st application and if both application are terminated then?????????????????

how can i start my main applcation.exe???????"




请编辑您的帖子,而不要发布假答案.

是的,您可以使用注册表在启动时启动您的应用,但不能重新启动它.

我告诉过你唯一的选择.无法阻止某人杀死这两个进程.您可以让每个进程搜索并启动另一个进程,如果您想与用户展开战争,但是如果用户无法杀死您的进程,您不能100%做到这一点,那么您就可以做到这一点对他们来说更难.一旦您的两个进程都死了,您将无能为力.




PLEASE edit your post, instead of posting fake answers.

yes, you can use the registry to start your app on startup, but not to restart it.

I told you the only option. There is no way to stop someone from killing both processes. You can make each process search for and start the other, if you want to start war with your users, but you can''t make it 100% the case that a user can''t kill your processes, you can just make it harder for them. Once your two processes are dead, there is nothing you can do.


您的服务可以做到这一点,是的.问题是,如果有人停止了该服务,那么它将无法正常工作.而且你不能阻止它.
Your service can do that, yes. The issue is, if someone stops the service, then it won''t work. And you can''t stop that.


这篇关于如何使我的应用程序始终运行(启动时启动,如果被杀死或崩溃则重新启动)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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