如何在Windows服务中访问剪贴板 [英] how to access clipboard in windows service

查看:717
本文介绍了如何在Windows服务中访问剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问剪贴板数据并在 windows服务(System.ServiceProcess.ServiceBase)中收听剪贴板消息
我想使用功能"AddClipboardFormatListener"和"RemoveClipboardFormatListener",但是这些功能需要 winform句柄

所以如何解决这个问题

I want to access clipboard data and listen to the message of clipboard in a windows service(System.ServiceProcess.ServiceBase)
I want to use the function "AddClipboardFormatListener" and "RemoveClipboardFormatListener" but these function need a winform handle

so how to do this problem

推荐答案

这似乎是一件很奇怪的事情,因为默认情况下剪贴板位于与桌面完全独立的线程上是.服务不是真正为UI交互设计的.我会考虑(如果正在传递数据)使用事件聚合器或中介程序/信使模式来传递数据????
That seems a very strange thing to do as the Clipboard in by default on a completely separate thread to the desktop which is where the clipboard is. A service is not really designed for UI interactions. I would consider (if data is being passed around) to use an event aggregator or mediator / messenger pattern to pass data around????


在某些情况下没有这种可能性:
首先,所有以LocalService登录类型运行的NT服务都与登录的用户会话ID不同,该ID等于0.这意味着该类型的服务具有自己的桌面实例和自己的会话变量.因此,此服务类型无权访问用户剪贴板.

解决方法是,我可以建议U,从已记录的用户NT帐户的名称运行此服务.然后,您可以通过在Net环境中使用Process类来获取@ Explore @进程的窗口句柄,然后检索Explore进程的句柄以进一步传递给您的api函数.
There is no such possibility in some cases:
First of all, all NT services which runs on as LocalService logon type , has a differ from logged user session ID, which equals to 0. That means, that this type of services has own desktop instance and own session variables.So this service type do not have access to user clipboard.

As a workaround, i could advice to U, run this service from the name of logged user NT account. Then you can get window handle of @Explore@ process by using Process class in Net environment, and after that retrieve handle of Explore process to further passing to your api functions.


这篇关于如何在Windows服务中访问剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆