在 Java 内置的 Windows 服务中捕获 Windows 关闭、注销和重新启动? [英] Capture Windows shutdown, log off and restart in Windows service built in Java?

查看:37
本文介绍了在 Java 内置的 Windows 服务中捕获 Windows 关闭、注销和重新启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在用 Java 构建的 Windows 服务中捕获 Windows 注销或/和关闭事件?

Is there a way to catch a Windows log off or/and shutdown event in a Windows service built in Java?

我想在 Windows 服务中捕获 Windows 事件,捕获后我想发送邮件.

I want to capture windows event in a Windows service and after capturing I want to send an mail.

推荐答案

我认为这里没有纯 Java 解决方案.

I do not think that you have a pure Java solution here.

我可以看到两种方式.

您可以将您的进程作为 Windows 服务运行.因此,您可以假设,如果它发生故障,它会与操作系统关闭进程一起发生.它不是 100% 正确,但相对简单.

You can run your process as a Windows service. So, you can assume that if it is going down it happens together with the OS shutting down the process. It is not 100% correct but relatively simple.

另一种方法是找到一些在操作系统宕机时启动的进程,并尝试对进程执行轮询.或者,您可以使用 WMI 事件.要从 Java 连接到 WMI,您可以使用以下之一:JaWinJ-integra, J-interop 或在 VBScript 或 JScript 中创建您自己的 WMI 脚本并使用 CScript 从 Java 运行它.

Another way is to find some process that starts when the OS is going down and try to perform polling on processes. Alternatively you can probably use WMI events. To connect to WMI from Java you can use one of: JaWin, J-integra, J-interop or create your own WMI script in VBScript or JScript and run it from Java using CScript.

这篇关于在 Java 内置的 Windows 服务中捕获 Windows 关闭、注销和重新启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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