完成任务后,我想向用户显示一些消息。但是该应用程序是作为服务运行的,因此无法使用UI组件。
Microsoft文档说我们可以使用Win32 API: wtssendmessage
显示对话框。我浏览了JNA文档,但找不到此特定内容的任何参考。我想为Java应用程序这样做。有办法通过JNA吗?
链接到WTSSENDMESSAGEA的文档:
这是Microsoft:Microsoft:
I want to display some message to the user when a task is completed. But the Application is running as a service, so it's not possible to use a UI component.
Microsoft documentation says we can use win32 API: WTSSendMessage
to show a dialog box. I went through the JNA documentation but couldn't find any reference for this specific thing. I want to do this for a Java application. Is there a way through JNA?
Link to the documentation of WTSSendMessageA: https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtssendmessagea
Here are some other ways suggested by Microsoft:
https://learn.microsoft.com/en-us/windows/win32/services/interactive-services?redirectedfrom=MSDN
发布评论
评论(1)
根据您提供的链接 ,服务可以
JNA由
JNA
伪像的基本功能和jna-platform
trafact中的用户分配的映射组成。尽管JNA中存在WTSAPI32
类,但只有某些DLL的功能已映射,但WTSSENDMESSAGE
均未映射。我注意到您将文档链接到-A后缀版本:这是不适用于任何现代版本Windows的“ ANSI”映射。如果您使用Winapi默认类型映射器映射非填充版本,它将自动选择正确的-a或-w后缀版本(区别在于-w使用UTF16宽字符串,而-a使用8位ASCII)。但是为了方便起见,您只需映射-w版本,
wtssendmessagew
。看一下参数列表,您需要:
handle
从wtsopenserver
发送,
wtsopenserver
状态这已经在JNA中映射(这是
handle
包装null)。因此,您只需要映射
wtssendmessage
函数即可。类型映射很简单。处理
和lpwstr
在JNA中映射,您应该使用int
dword
args和boolean
bool
。您将使用接口,并扩展现有的JNA映射以获取对其功能的访问:然后使用功能。我们可以使用当前的服务器句柄,当前会话,创建我们的字符串传递,使用“确定”样式,并通过将false作为等待参数来忽略超时/响应。
这都是未经测试的。您需要适当的进口。
According to the link you provided, a service can
JNA is comprised of the base functionality in the
jna
artifact and user-contributed mappings in thejna-platform
artifact. While theWtsapi32
class exists in JNA, only some of that dll's functions have been mapped, but notWTSSendMessage
.I note you linked the docs to the -A suffixed version: this is the "ANSI" mapping that does not apply to any modern version of windows. If you map the un-suffixed version using the WinAPI default type mapper, it will automatically choose the correct -A or -W suffixed version (the difference is that -W uses UTF16 wide strings while -A uses 8-bit ASCII). But for your convenience you can just map the -W version,
WTSSendMessageW
.Looking down the list of arguments, you need:
HANDLE
obtained fromWTSOpenServer
For the server handle, the docs for
WTSOpenServer
stateThis is already mapped in JNA (it's a
HANDLE
wrapping null).So you just need to map the
WTSSendMessage
function. The type mappings are straightforward.HANDLE
andLPWSTR
are mapped in JNA, and you should useint
for theDWORD
args andboolean
forBOOL
. You'll use an interface, and extend the existing JNA mapping to obtain access to its functions:Then use the functions. We can use the current server handle, the current session, create our strings to pass, use the "OK" style, and ignore the timeout/response by passing false as the wait parameter.
This is all untested. You'll need appropriate imports.