Sign in to follow this  
Followers 0
mkizer

Weird RunWait situation with Remote Desktop

4 posts in this topic

I'm writing a little script to launch a few Remote Desktop windows, log in and position them across my monitors. Right now I just have the script opening four windows and attempting to login and noticed a weird situation.

First, here is the code:

; Variables-
$RD = "C:\Windows\system32\mstsc.exe"
$RDP = "C:\Documents and Settings\mkizer\Desktop\Servers\"


; Script Start-
RunWait($RD & ' "' & $RDP & 'Prod App - COSDA256.rdp"')
WinWaitActive("Prod App - COSDA256 - cosda256 - Remote Desktop")
Sleep(1000)
Send("!ulogonID{TAB}secretpassword{Enter}")
Sleep(1000)

RunWait($RD & ' "' & $RDP & 'Prod App - COSDA257.rdp"')
WinWaitActive("Prod App - COSDA257 - cosda257 - Remote Desktop")
Sleep(1000)
Send("!ulogonID{TAB}secretpassword{Enter}")
Sleep(1000)

RunWait($RD & ' "' & $RDP & 'Prod App - COSDA259.rdp"')
WinWaitActive("Prod App - COSDA259 - cosda259 - Remote Desktop")
Sleep(1000)
Send("!ulogonID{TAB}secretpassword{Enter}")
Sleep(1000)

RunWait($RD & ' "' & $RDP & 'Prod App - COSDA260.rdp"')
WinWaitActive("Prod App - COSDA260 - cosda260 - Remote Desktop")
Sleep(1000)
Send("!ulogonID{TAB}secretpassword{Enter}")
Sleep(1000)

Note: The .RDP files saved in the "Servers" directory on the desktop are simply saved from the Remote Desktop client. They contain all of the info (other than logon ID and password) required to connect to each specific server.

OK, time for the weird part...

The first time I launch this script, the first server's Remote Desktop window is displayed, but nothing else happens. So I manually hit cancel and the window closes. The A3 script is still running, but paused in the System Tray.

I run the script again. This time, the first window is displayed, the logon ID and password are sent, enter is pressed and the second server's window appears, but nothing else happens. I cancel that window, and log off of the first server. Note that now two copies of this script are now paused in the System Tray.

I run the script again. First server...successful, second server...successful, third server... nothing. So, cancel and log off of the other two servers. Now there are three paused scripts.

Basically the same drill for the fourth server... but after I cancel and log off of all of those servers (while leaving the now four paused scripts in the System Tray), every time I run the script all four servers are logged into successfully.

Anything obvious that I am missing here?

Thanks,

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

...OK, time for the weird part...

The first time I launch this script, the first server's Remote Desktop window is displayed, but nothing else happens. So I manually hit cancel and the window closes. The A3 script is still running, but paused in the System Tray.

I run the script again. This time, the first window is displayed, the logon ID and password are sent, enter is pressed and the second server's window appears, but nothing else happens. I cancel that window, and log off of the first server. Note that now two copies of this script are now paused in the System Tray...

Don't use RunWait... use Run.

From the helpfile for RunWait:

After running the requested program the script pauses until the program terminates. To run a program and then immediately continue script execution use the Run function instead.

The first copy of your script is waiting for mstsc to terminate before going on.

Once you manually terminated the first mstsc, the first script was sitting at the WinWaitActive line.

The second copy of your script started the first remote desktop session again and waited - while the first copy of your script filled in the info that you wanted... and so on.

Take a look at this post and see if you could use ControlSend like that code did:

http://www.autoitscript.com/forum/index.ph...ndpost&p=128462

While you are at it, take a look at this:

http://www.autoitscript.com/autoit3/docs/faq.htm#14

Also, you might want to look into using one of the many favors of VNC instead of Remote Desktop... or as a backup to it. Most flavors of VNC have a "view only" mode so that no errant commands are sent to the servers.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Don't use RunWait... use Run.

Ah, I knew I overlooked something simple... I've been away from AutoIt coding for too long I guess...

Take a look at this post and see if you could use ControlSend like that code did:

http://www.autoitscript.com/forum/index.ph...ndpost&p=128462

Yeah, that looks even better. I'll probably end up just launching Remote Desktop and piping in the server info for my final version (there are going to be 19 servers I need to connect to for this particular task).

Also, you might want to look into using one of the many favors of VNC instead of Remote Desktop... or as a backup to it. Most flavors of VNC have a "view only" mode so that no errant commands are sent to the servers.

Yeah, I already use UltraVNC for most remote work (it has file transfer capabilities and is generally pretty snappy), but these servers are here at work in a secure environment with only Terminal Services access allowed...so I am stuck.

Thanks for the quick help!

Share this post


Link to post
Share on other sites

Glad to help.

Welcome to the forums.

Hang around a while :-)


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0