我创建了一项服务。它工作正常..安装、启动、停止等。我正在尝试使用 JNA 捕获某些内容。这是我正在捕获的代码。
PointerType hwnd = User32.INSTANCE.GetForegroundWindow(); // then you can call it!
User32.INSTANCE.GetWindowTextA(hwnd, windowText, 512);
log.info("Window title is: "+Native.toString(windowText));
记录器存储这不是预期的
17:54:59,472 INFO rkactivityclientlog:33 - Window title is:
17:55:00,477 INFO rkactivityclientlog:33 - Window title is:
如果我 try catch intbyreference 它会打印 0。
编辑::如果我尝试获取任何其他对象(例如日期)..它会正常出现..就像
18:04:15,885 INFO rkactivityclientlog:39 - Time is: Wed Jun 12 18:04:15 IST 2013
但它没有捕获 native 变量:(
但是我可以在标准输出中捕获所需的信息。
请帮忙..
最佳答案
从 Windows Vista 开始,服务无法访问桌面。请参阅关于 Interactive services 的 MSDN 文章。现在,服务在与任何登录用户不同的 session 中运行。
Services cannot directly interact with a user as of Windows Vista.
为了访问用户桌面上的窗口信息,您需要编写一个可以在用户特定上下文中执行的应用程序。然后,该应用程序需要通过某种 RPC 机制与您的服务进行通信。
原因是服务通常以非常高的权限运行。过去,交互服务一直是安全漏洞的根源。特别是,攻击者能够使用一种名为 shatter attacks 的技术。升级权限。
A shatter attack takes advantage of a design flaw in Windows's message-passing system whereby arbitrary code could be injected into any other running application or service in the same session, that makes use of a message loop. This could result in a privilege escalation exploit.
关于java - Windows 服务无法访问某些信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17065622/