在计算机ahutsdown之前执行代码 [英] Execute code before computer ahutsdown

查看:110
本文介绍了在计算机ahutsdown之前执行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在计算机关闭,注销,休眠或睡眠之前用java执行某段代码?

我试图在lubuntu的终端中使用runlevel来尝试听一个0,如果发生这种情况,执行代码,但那不起作用。

我也尝试在关机时执行joptionpane,通过监听app退出,但这也行不通。

有人可以给我另一个建议吗?

谢谢。

Is there some way to execute some piece of code before the computer shutsdown, logs off, hibernates or sleeps, with java?
I tried to use runlevel in a terminal in lubuntu, to try and listen for a 0, and if that happened, execute the code, but that did not work.
I also tried executing a joptionpane in shutdown, by listening for app exit, but that also did not work.
Can someone give me another advice?
Thanks.

推荐答案

我不认为这是可能的纯Java。通过在Windows系统中注册某些消息,可以在C / C ++中完成。您需要检查Linux文档以查看它是否提供了类似的机制。
I do not think this is possible in pure Java. It is possible to do it in C/C++ by registering for certain messages in a Windows system. You need to check the Linux documentation to see if it provides a similar mechanism.


这篇关于在计算机ahutsdown之前执行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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