Sendmessage from NT Service to remote desktop sess

2019-02-16 01:51发布

问题:

How can i send a sendmessage & postmessage from nt service to an application which launched in a remote desktop session? currently i temporarily solved this problem via udp communications between applications.

回答1:

You cannot send messages across session boundaries. So you need an IPC solution like TCP/IP, sockets, named pipes etc.



回答2:

Make a program that does a sendmessage/postmessage:

program sendit; uses converters; begin exitcode:=sendmessage(covert1(paramstr(1)),convert2( .... etc end.

Then run it in the right session with CreateProcessAsUser. You can wait (WaitForSingleObject) for the program to exit, at which point the sendmessage completed. It's very slow though :).

You can also go with pipes/IPC, but you can still launch the "server" using CreateProcessAsUser. Use Jwa for getting tokens and such.

And use better names than I just did :).



回答3:

Use the WTSSendMessage api: Displays a message box on the client desktop of a specified Remote Desktop Services session.

http://msdn.microsoft.com/nl-nl/library/windows/desktop/aa383842(v=vs.85).aspx

Or use the Jedi Windows Security library which wraps this in nice delphi like objects