C# 关闭RDP时出现SendKeys.SendWait权限被拒绝错误

C# 关闭RDP时出现SendKeys.SendWait权限被拒绝错误,c#,winapi,windows-server-2008-r2,rdp,C#,Winapi,Windows Server 2008 R2,Rdp,我正在尝试启动一个程序,我必须在其中输入登录名和密码 要模拟击键,我将使用以下代码: System.Windows.Forms.SendKeys.SendWait(login + "\t" + password + "\n\r"); 不幸的是,我要在Windows server 2008 R2 x64操作系统的服务器上执行所有这些操作,并且我必须使用RDP。当RDP连接处于活动状态时,一切正常,但如果RDP窗口关闭或最小化,SendWait将调用异常,并显示消息“permission deni

我正在尝试启动一个程序,我必须在其中输入登录名和密码

要模拟击键,我将使用以下代码:

System.Windows.Forms.SendKeys.SendWait(login + "\t" + password + "\n\r");
不幸的是,我要在Windows server 2008 R2 x64操作系统的服务器上执行所有这些操作,并且我必须使用RDP。当RDP连接处于活动状态时,一切正常,但如果RDP窗口关闭或最小化,SendWait将调用异常,并显示消息“permission denied”

当RDP断开连接时,如何模拟击键


谢谢。

您可以使用中描述的方法

使用以下命令创建批处理文件,并将其保存到要保持解锁的工作站的桌面:我已将我的文件命名为Logoff.bat

START C:\Windows\System32\tscon.exe 0 /dest:console
START C:\Windows\System32\tscon.exe 1 /dest:console
START C:\Windows\System32\tscon.exe 2 /dest:console
START C:\Windows\System32\tscon.exe 2 /dest:console
START C:\Windows\System32\tscon.exe 3 /dest:console
START C:\Windows\System32\tscon.exe 4 /dest:console
START C:\Windows\System32\tscon.exe 5 /dest:console
Tscon.exe是windows安装的标准配置,专门用于使以前锁定的控制台处于解锁状态。请参阅此链接:


下次使用远程桌面登录工作站时,不要以正常方式注销,而是运行批处理文件-在我的例子中是“Logoff.bat”,这将终止远程桌面连接并注销,但随后将继续以未锁定状态运行任何脚本,就像有人实际登录一样。

听起来很公平,再也没有可将密钥发送到的桌面了。