在服务器上的应用程序之间发送点击和击键 [英] Sending Clicks and Keystrokes between Applications on a Server

查看:65
本文介绍了在服务器上的应用程序之间发送点击和击键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果主应用程序和辅助应用程序在未连接监视器的专用Windows服务器上,是否可以使用sendkeys或user32 api调用自动控制c#中的另一个应用程序?

我已经尝试过了,但是仅当我使用远程桌面连接到计算机时,它才有效.如果没有监视器(或鼠标或键盘!),我猜测实际上没有ui,因此ui调用失败.例如,我可以找到窗口句柄,但是即使调到前台调用也不起作用.

Is there a way to automate control of another application in c# using sendkeys or user32 api calls if the main and secondary applications are on a dedicated windows server that does not have a monitor connected?

I have tried but it only works when I am connected to the machine with Remote Desktop. Without a monitor (or mouse or keyboard!) I''m guessing there is effectively no ui so the ui calls fail. For example I can find the window handles but even bring to foreground calls don''t work.

Any ideas on alternative solution or approach here would be greatly appreciated!

推荐答案

从来没有尝试过-所以我在这里都猜到了...

我的第一个想法是:这些应用程序(需要UI)如何在没有UI的会话中在服务器上运行?"我可以看到您可以在远程桌面会话中启动应用程序-但是,当您注销(或者只是断开连接?)时,应用程序会如何处理?

在桌面设备上,当您注销时,所有应用程序都已关闭-因此,我想必须以某种方式将任何用户"应用程序(即需要UI的应用程序)与用户会话相关联.

因此,必然的结果是,如果应用程序在已登录但已断开连接的会话中运行,则它们不知道当前没有连接显示器/键盘,因此您应该能够插入事件进入UI消息循环.

嗯-但是您说可以找到窗户把手.未连接远程桌面会话时可以执行此操作吗?如果是这样,那会让我的理论大跌眼镜. :((

因此,这些都不是解决方案的主意.

您对这些应用的实施有多少控制权?

您可以重写它们,以便它们不需要UI吗?如果它们在服务器上运行(作为服务器应用程序),这似乎很有意义.然后,您需要做的是设计一个他们可以响应的协议.请记住,没有UI意味着没有免费内置"消息泵-您将必须编写自己的消息.

听起来您有时想要自动控制它们,有时想要通过UI控制它们.如果是这种情况,则将应用程序划分为可工作的位"和具有UI的位"将是更强大的体系结构-在此无需重新安装Win32窗口体系结构和消息泵来完成原本不希望的事情.

当然,您可能无法进行这种更改.在这种情况下,我可能根本没有帮助.抱歉,是这种情况. :-O
Never tried it - so I''m all guesses here...

My first thought is: "How are these apps (that need a UI) running on a server in a session without a UI?" I can see that you could start the apps in your remote desktop session - but what happens to the apps when you log out (or are you just disconnecting?)?

On a desktop box, when you log out, all your apps are closed - so any ''user'' app (i.e. app that needs a UI) I imagine must be associated with a user session somehow.

So, the corollary would be that if the apps are running in a logged-in-but-disconnected session, then they don''t know that there''s no current display / keyboard attached, and you should be able to inject events into the UI message loop.

Hmm - but you say you can find the window handles. You can do this when you are NOT connected in a remote desktop session? If so, that blows my theory out of the water. :((

So, none of that was anywhere near an idea for a solution.

How much control do you have over the implementation of these apps?

Can you rewrite them so they don''t need a UI? If they''re running on a server, as server apps, that would appear to make sense. Then what you need to do is design a protocol that they can respond to. Remember, no UI means no ''built in for free'' message pump - you''ll have to write your own.

It sounds like you sometimes want to control them automatically and sometimes via a UI. If that''s the case then partitioning the app into the ''bit that does the work'' and the ''bit that has a UI'' would be a more robust architecture - where you''re not finagling the Win32 windows architecture and message pump to do things it was not intended for.

Of course, you may not be able to make that kind of change. In which case I''ve probably been no help at all. Sorry if that''s the case. :-O


这篇关于在服务器上的应用程序之间发送点击和击键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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