且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测在Windows上运行的Java服务用户的活动?

更新时间:2023-10-24 18:24:10

您不能监视直接从服务用户的活动。这项服务将运行在从用户的活动不同的窗口站,因此将无法挂接到该活动(除通过将需要用C语言编写的筛选器驱动程序)。

You cannot monitor user activity directly from a service. The service will be running in a different window station from the users activities and so will have no way to hook into that activity (except through filter drivers that would need to be written in C).

所以,你需要一个运行在用户的桌面和挂接到键盘和鼠标活动的客户端应用程序。你会做到这一点通过两个调用Windows API SetWindowsHookEx函数使用JNI(低级别的键盘和鼠标钩子)。要监视活动的应用程序然后将需要处理的键盘和鼠标钩子消息。

So you will need a client application that runs in the user's desktop and hooks into the keyboard and mouse activity. You would do that via two calls to the Windows API SetWindowsHookEx (for low level keyboard and mouse hooks) using JNI. To monitor activity the application would then need to process the keyboard and mouse hooks for messages.

您可以通过添加一个条目添加到注册表的Run键启动应用程序自动启动,或者你可以让你的服务监视器有关事件的会话日志和launch该应用程序它。然后用户会话应用可以或者处理信息本身或它经由管道或插座传递给服务。

You could launch the application as auto-start by adding an entry to the registry's Run key or you could have your service monitor for session log on events and launch the application from it. Then the user session application could either process the information itself or pass it to the service via a pipe or socket.