Automated Send Keys Failing When No RDP
Asked Answered
T

1

6

I have a VM that I wish to run an automated task on (i.e. the automated task runs on the actual VM).

The VM is a Windows 2008 server.

I have added the task into the task scheduler, and when I'm logged into the machine via RDP I can run the task by right clicking, Run.

However, when my RDP session is turned off, (but the user on the VM is still logged in) the task trys to run, but only opens notepad.exe, but does not write the text.

The vbs script is as follows (simplified for our use here...);

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "Notepad.exe"
Do Until Success = True
Success = objShell.AppActivate("Notepad")
Wscript.Sleep 1000
Loop
objShell.SendKeys "This is a test."

I have has this task working perfectly on a Windows XP machine and I just cant understand what is causing the issue.

It seems as if there is no keyboard found on the VM when not connected via RDP. When connected via RDP MSTSC sends the VM my keyboard and can then run the task correctly.

Thanks,

David

Trine answered 19/4, 2013 at 10:42 Comment(0)
T
7

OK,

So think i figured it out...

The problem is that once you log out with remote desktop, then the server is locked and no scripts can run. I have tried various options, including ControlSend and ControlClick commands, but without any success.

The solution is as follows: Create a batch file with the following commands and save it to the desktop of the workstation you want to keep unlocked: I have named my file 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 comes standard with your windows installation and is specifically created to leave a Previously-Locked Console Unlocked. See this link: http://support.microsoft.com/kb/302801

The next time you log in to the workstation with remote desktop, do not log out the normal way, but run you batch file - in my case "Logoff.bat" This will terminate your Remote Desktop connection and log you out, but will then continue in an unlocked state for any scripts to run as if someone is actually logged in.

Trine answered 22/4, 2013 at 15:11 Comment(2)
kind a late lol, seems like it works but fucks up the resolution, when I log back in the screen is less than half the size (its fixed right away) but its causing issues to my clicks.... any ideas?Farlee
It works like a champ!, Thanks @David. My only suggestion is, it might not be always 0-5 sessions, it could go randomly, as in my case it was 99. So I did like this- for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do ( %windir%\System32\tscon.exe %%s /dest:console ) Please refer below link for more info- support.smartbear.com/testcomplete/docs/testing-with/running/…Bouie

© 2022 - 2024 — McMap. All rights reserved.