断开连接的 RDP 会话上的 Sendkeys [英] Sendkeys On Disconnected RDP Session
问题描述
我有一个预定的 VB 应用程序.它专注于一些 cmd 窗口并执行 sendkey 操作.当我打开 RDP 会话时,这工作正常,只有当我断开连接(而不是注销)时才会出现问题.(此任务在虚拟化服务器上运行).
I have a VB application which is scheduled. It focuses on some cmd windows and performs sendkey actions. This works fine when I have the RDP session open, it's only when I disconnect (not logoff) that the issue occurs. (This task is running on a virtualised server).
当我在任务运行后再次打开 RDP 会话时,应用程序抛出了有关登录权限的错误.我认为这是因为用户被锁定,因此无法执行操作?
When I open the RDP session again after the task has ran, the application has thrown an error regarding the login permissions. I presume this is because the user is locked and therefore can't perform the actions?
我需要找到解决方法,非常感谢您的帮助!
I need to find a way around this, any help is much appreciated!
推荐答案
不要使用 SendKeys.
Don't use SendKeys.
相反,如果您有一个在命令提示符下运行的程序,请确保 VB.NET 程序是使用 Process.Start
打开它(或它们)的程序,并设置 True
的 ProcessStartInfo
对象的 >RedirectStandardInput 属性.然后将命令传递到进程的 StandardInput
属性中,就像写入文件一样.
Instead, if you have a program running in a command prompt, make sure the VB.NET program is the one to open it (or them) with Process.Start
, and set the RedirectStandardInput
property of the ProcessStartInfo
object you pass to True
. Then pass commands into the process's StandardInput
property as though writing to a file.
这将避免任何焦点更改问题、与锁定屏幕会话有关的任何问题、大多数(如果不是全部)完整性级别的潜在问题、大多数(如果不是全部)时间问题,以及可能其他一些我没有想到的问题.
This will avoid any focus-change problems, any problems to do with locked screen sessions, most if not all potential problems with integrity levels, most if not all problems with timing, and probably some other stuff I'm not thinking of.
这篇关于断开连接的 RDP 会话上的 Sendkeys的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!