问题
I am trying to get clipboard events using SetClipboardViewer. It works in a windows form when i override the function:
protected override void WndProc(ref Message m)
that belongs to the base class System.Windows.Forms.
The problem is that i want to do it in a windows service.
Does someone knows how to get the clipboard events in a windows service?
Thanks.
回答1:
Clipboard belongs to the session (actually the session's winstation), and there's no interactive user to do a clipboard copy in a service session. Of course you can have a clipboard listener process to relay the clipboard changes from an interactive session. You can use any protocol that works across the session, like sockets, shared memory or named pipe. Rdpclip.exe acts like one, though it sends data out via WTS virtual channels.
Some clipboard contents make sense when crossing the session boundary (e.g. CF_TEXT), some don't (e.g. CF_HDROP with paths from a mapped drive).
来源:https://stackoverflow.com/questions/14253313/how-to-use-setclipboardviewer-function-in-windows-service-c