Jump to content
Sign in to follow this  
cbm128

Interaction with RDP client

Recommended Posts

cbm128

Hello,

I'm trying to use AutoIt to solve an annoying issue:

here we use MS Terminal Servers to access the internet (the internal LAN is physically separated from the Internet), to reduce the workload there is a server policy enabled that will disconnect inactive clients after around 15 minutes, disconnected sessions are then logged out after around 60 minutes.

While this is OK for regular users who do not need internet very often, it is a major distress and waste of time to me (sometimes I have to login more than 10 times a day, and most times it take minutes once all login scripts are run).

I have no influence on the Terminal Servers setup, all I can do is on the client.

So I thought to use AutoIt to create a script that will prevent these timeouts to happen by sending keystrokes (I though of sending the LWIN key followed by ESC) to the RDP session.

The only way I could make it work was by using the "Send" function, but this is also not very professional because it needs to have the RDP windows in focus and will interrupt what I'm doing/typing in other windows.

I was hoping of using the "ControlSend" function because it can interact with unfocused windows (allowing it to work also when the session is locked) but it seems not to work in my setup.

I am sure that the correct parameters to identify the right window are passed to it because if I use "ControlFocus" with the same parameters the RDP session is identified and focused.

Also, even stranger, if I use the script while I have the "Window Info" application open on the local computer and a notepad open on the remote one (just to see if something is typed in by the script) and I send an arbitrary string of text, sometimes I can see it in the 'visible text' section of "Window Info" but it does not get to the Notepad.

Some additional info:

- WinXP English SP2

- AutoIt v3

- Remote Desktop Connection V6.0 (tried also with default XP RDP client)

- CUT&PASTE between the RDP session and the local client are disabled by a policy on the server

- the RDP window is not in full screen mode

- there is only one RDP window active on my local PC

I'm puzzled, somebody has any idea?

Thanx.

"Window Info" for the RDP session:

#############################################

>>>> Window <<<<

Title: internet - xxxxx.yyyyyy.zz - Remote Desktop

Class: TSSHELLWND

Position: 0, 0

Size: 1280, 1024

Style: 0x160A0100

ExStyle: 0x00000000

Handle: 0x00BE029C

>>>> Control <<<<

Class: OPWindowClass

Instance: 2

ClassnameNN: OPWindowClass2

Advanced (Class): [CLASS:OPWindowClass; INSTANCE:2]

ID:

Text: Output Painter Window

Position: 0, 0

Size: 1280, 1024

ControlClick Coords: 868, 456

Style: 0x54000000

ExStyle: 0x00000004

Handle: 0x00060586

>>>> Mouse <<<<

Position: 868, 456

Cursor ID: 0

Color: 0xFFFFFF

>>>> StatusBar <<<<

>>>> Visible Text <<<<

internet - xxxxx.yyyyyy.zz - Remote Desktop

Input Capture Window

Output Painter Window

>>>> Hidden Text <<<<

Output Painter Window

#############################################

Edited by cbm128

Share this post


Link to post
Share on other sites
JSThePatriot

I would like to also request the code you've already tried. It's easier to debug what you've done, than for us to spend our time re-writing something you probably have a good start on.

Thanks,

Jarvis


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites
cbm128

I just was ashamed to post such a silly code >_<

Here it is the one that works by activating the window and sending the keys:

WinActivate("internet", "")
If WinActive ("internet") Then
    Send("{LWIN}")
    Send("{ESC}") 
EndIf

Here the one I'd like to make work (does not require focus):

ControlSend ( "internet", "Output Painter Window", "[CLASS:OPWindowClass; INSTANCE:2]", "{LWIN}{ESC}")

If I try the following code the correct window is Activated

ControlFocus("internet", "Output Painter Window", "[CLASS:OPWindowClass; INSTANCE:2]")

Share this post


Link to post
Share on other sites
JSThePatriot

Well don't be ashamed. You are showing that you're trying to get this done, and not simply asking for someone to do all the work for you, and you never know this post may help someone later down the road that was trying the same things you were.

What you are noticing is that you are able to activate the "Window" but not send anything to a "control". Since there isn't much of a control to send to...here are some notes I pulled out of the help file about ControlSend

Return Value

Success: Returns 1.

Failure: Returns 0 if window/control is not found.

Remarks

ControlSend works in a similar way to Send but it can send key strokes directly to a window/control, rather than just to the active window.

ControlSend is only unreliable for command prompts as that works differently to normal windows (seems to check physical states rather than accepting the keystroke messages). For normal windows ControlSend should be way more reliable than a normal Send - and yes it does send shift, ctrl, alt etc.

As mention in the Send help the keyboard that send different chars when in CAPS LOCK and using the Shift Key cannot be simulated. An example is the Czech Keyboard. A good workaround is to use the ControlSetText.

The control might first need to be given focus with the ControlFocus command, specially when referencing an controlID created by the script itself.

Opt("SendKeyDelay",...) alters the the length of the brief pause in between sent keystrokes.

Opt("SendKeyDownDelay",...) alters the length of time a key is held down before being released during a keystroke.

If you notice it says that it has a hard time with a command prompt. I think you're running into the same issue.

I think your only option is to use Send. Maybe you can have it pop up a message box that allows you to cancel it, or it can time out and continue the script?

I hope this helps,

Jarvis


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites
cbm128

What you are noticing is that you are able to activate the "Window" but not send anything to a "control". Since there isn't much of a control to send to...here are some notes I pulled out of the help file about ControlSend If you notice it says that it has a hard time with a command prompt. I think you're running into the same issue.

I think your only option is to use Send. Maybe you can have it pop up a message box that allows you to cancel it, or it can time out and continue the script?

Thanks for the reply,

I did read already all the relevant (to me ;-) man, ops, help >_< pages and noticed the issue with command prompt, I just thought that it was not that related to an RDP session.

Well, as I said, it is already working in the odd way described. I was just hoping that somebody had ideas on how to make it less obtrusive.

Massimo

Share this post


Link to post
Share on other sites
JSThePatriot

No problem. I wish I could help more and give you the less obtrusive manner you were looking for, but there will probably be something that is obtrusive about it. You could try maybe popping up a TrayTip() before it happens so you know it's about to. This way you're notified.

Jarvis


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

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  

×