我试图启动一个程序,我必须在其中输入登录名和密码。
使用下一个代码来模拟击键:
System.Windows.Forms.SendKeys.SendWait(login + "\t" + password + "\n\r");
不幸的是,我将在使用Windows Server 2008 R2 x64操作系统的服务器上执行所有这些操作,并且我必须使用RDP。当RDP连接处于活动状态时,一切正常,但如果RDP窗口关闭或最小化,SendWait将调用异常,并显示消息'权限被拒绝'。
如何在断开RDP时模拟击键?
感谢。
答案 0 :(得分:1)
您可以this
使用David Johnson中描述的方法使用以下命令创建批处理文件并将其保存到要保持解锁的工作站的桌面:我已将文件命名为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安装的标准配置,专门用于保持以前锁定的控制台解锁。请看这个链接:http://support.microsoft.com/kb/302801
下次使用远程桌面登录工作站时,请不要以正常方式注销,而是运行批处理文件 - 在我的情况下“Logoff.bat”这将终止远程桌面连接并将您注销,但是,然后将继续处于解锁状态,以便任何脚本运行,就像有人实际登录一样。