windows 注销后如何启动应用程序而不会被杀死?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8503075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to start a application without getting killed after log off?
提问by Christian Ammer
I have a Java application which should run on a server machine in the background (the application can be started by a command without GUI). The problem is: When I log off from the server, the application gets killed. I'm looking for something similar like nohup
under Linux. I found some solutions, but I'm unsure, what is the best for my situation (Windows Server 2003, Java Application run from BAT-Skript, restart after booting the machine)? What are the pros and cons of the solutions?
我有一个 Java 应用程序,它应该在后台的服务器机器上运行(该应用程序可以通过没有 GUI 的命令启动)。问题是:当我从服务器注销时,应用程序被杀死。我正在寻找类似nohup
在 Linux 下的东西。我找到了一些解决方案,但我不确定什么是最适合我的情况(Windows Server 2003,从 BAT-Skript 运行的 Java 应用程序,启动机器后重新启动)?解决方案的优缺点是什么?
- psexec: Do the process really need to run under the SYSTEM account?
- Combination of
instsrv
andsrvany
: But srvany should should never be used in a production environment - I have started the application with the scheduled tasks with the option run as
NT AUTHORITY\SYSTEM
. But after log off, the application was still killed. Can I get this working? - The DOS Task Scheduler AT command
- psexec: 进程真的需要在SYSTEM账户下运行吗?
- 结合
instsrv
和srvany
:但是SRVANY应不应该在生产环境中使用 - 我已经使用计划任务启动了应用程序,并选择了 run as
NT AUTHORITY\SYSTEM
。但是注销后,该应用程序仍然被杀死。我可以让它工作吗? - 在DOS任务计划程序AT命令
采纳答案by Vadzim
Just to add to above answers.
只是为了补充上述答案。
Consider using http://wrapper.tanukisoftware.com. It's rather mature and popular (in contrast to ServiceEx and RunAsService).
考虑使用http://wrapper.tanukisoftware.com。它相当成熟和流行(与 ServiceEx 和 RunAsService 相比)。
回答by abatishchev
- Write a windows service (on Java, C# - I don't think it does matter)
- Start the app from your service
- 编写 Windows 服务(在 Java、C# 上 - 我认为这无关紧要)
- 从您的服务启动应用程序
or
或者
- Run your app as a window service using 3d party utility
- 使用3d 派对实用程序将您的应用程序作为窗口服务运行
回答by ChrisBD
The only way in which you can get a process to run without a user being logged in is to have the process run as a windows service or at the very least called by a windows service.
在没有用户登录的情况下让进程运行的唯一方法是让进程作为 Windows 服务运行,或者至少由 Windows 服务调用。
回答by CoreTech
Yes, a Windows Service is definitely the way to go but there are a few things to watch out for when you run a Java application as a Windows Service. Most of them are covered in this tutorial showing how to setup a java application with our commercial run-anything-as-a-service application, AlwaysUp:
是的,Windows 服务绝对是可行的方法,但是当您将 Java 应用程序作为 Windows 服务运行时,需要注意一些事项。本教程介绍了其中的大部分内容,展示了如何使用我们的商业运行即服务应用程序 AlwaysUp 设置 Java 应用程序:
http://www.coretechnologies.com/products/AlwaysUp/Apps/RunJavaApplicationAsAService.html
http://www.coretechnologies.com/products/AlwaysUp/Apps/RunJavaApplicationAsAService.html
Beware: You will almost surely need the "-Xrs" flag on Windows 2003 to prevent the closing-on-logoff behavior but things can get tricky if you are catching shutdown events. Let me know if that is an issue for your situation.
注意:您几乎肯定需要 Windows 2003 上的“-Xrs”标志来防止关闭时注销行为,但如果您捕获关闭事件,事情会变得棘手。如果这对您的情况有影响,请告诉我。